-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_save_params.zig
More file actions
267 lines (221 loc) · 9.07 KB
/
test_cli_save_params.zig
File metadata and controls
267 lines (221 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
const std = @import("std");
const cli = @import("src/cli.zig");
const constants = @import("src/constants.zig");
// Integration tests for CLI save and auto-save parameters
// These tests verify the complete parsing workflow
test "CLI integration - parseArgs with save parameter" {
// Note: This test demonstrates the pattern for testing parseArgs
// In a real scenario, we'd need to mock std.process.argsAlloc
var allocator = std.testing.allocator;
// Test manual construction of CliArgs to verify structure
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "integration_test.cgol"),
.save_description = try allocator.dupe(u8, "Integration test save"),
.rows = 20,
.cols = 30,
.generations = 50,
.delay_ms = 100,
};
defer args.deinit(allocator);
// Validate the constructed args
try cli.validateArgs(args);
// Verify all fields are set correctly
try std.testing.expectEqualStrings("integration_test.cgol", args.save_file.?);
try std.testing.expectEqualStrings("Integration test save", args.save_description.?);
try std.testing.expect(args.rows.? == 20);
try std.testing.expect(args.cols.? == 30);
try std.testing.expect(args.generations.? == 50);
try std.testing.expect(args.delay_ms.? == 100);
}
test "CLI integration - parseArgs with auto-save parameters" {
var allocator = std.testing.allocator;
// Test auto-save configuration
var args = cli.CliArgs{
.auto_save_every = 25,
.save_prefix = try allocator.dupe(u8, "test_auto_"),
.save_description = try allocator.dupe(u8, "Auto-save test session"),
.rows = 15,
.cols = 25,
.generations = 200,
.delay_ms = 150,
};
defer args.deinit(allocator);
// Validate the constructed args
try cli.validateArgs(args);
// Verify auto-save fields
try std.testing.expect(args.auto_save_every.? == 25);
try std.testing.expectEqualStrings("test_auto_", args.save_prefix.?);
try std.testing.expectEqualStrings("Auto-save test session", args.save_description.?);
}
test "CLI integration - complex save configuration" {
var allocator = std.testing.allocator;
// Test complex scenario with multiple save-related options
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "complex_test.cgol"),
.save_description = try allocator.dupe(u8, "Complex test with manual and auto-save"),
.auto_save_every = 100,
.save_prefix = try allocator.dupe(u8, "backup_"),
.pattern_file = try allocator.dupe(u8, "patterns/glider.rle"),
.rows = 40,
.cols = 60,
.generations = 500,
.delay_ms = 80,
};
defer args.deinit(allocator);
// This should pass validation
try cli.validateArgs(args);
// Verify all save-related parameters
try std.testing.expectEqualStrings("complex_test.cgol", args.save_file.?);
try std.testing.expectEqualStrings("Complex test with manual and auto-save", args.save_description.?);
try std.testing.expect(args.auto_save_every.? == 100);
try std.testing.expectEqualStrings("backup_", args.save_prefix.?);
try std.testing.expectEqualStrings("patterns/glider.rle", args.pattern_file.?);
}
test "CLI integration - save parameter validation edge cases" {
var allocator = std.testing.allocator;
// Test case 1: Save file with path separators
{
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "saves/subdir/test.cgol"),
.save_description = try allocator.dupe(u8, "Save in subdirectory"),
};
defer args.deinit(allocator);
try cli.validateArgs(args);
try std.testing.expect(std.mem.indexOf(u8, args.save_file.?, "/") != null);
}
// Test case 2: Minimum auto-save interval
{
var args = cli.CliArgs{
.auto_save_every = 1,
.save_prefix = try allocator.dupe(u8, "min_"),
};
defer args.deinit(allocator);
try cli.validateArgs(args);
try std.testing.expect(args.auto_save_every.? == 1);
}
// Test case 3: Large auto-save interval
{
var args = cli.CliArgs{
.auto_save_every = 10000,
.save_prefix = try allocator.dupe(u8, "large_"),
};
defer args.deinit(allocator);
try cli.validateArgs(args);
try std.testing.expect(args.auto_save_every.? == 10000);
}
}
test "CLI integration - error scenarios for save parameters" {
var allocator = std.testing.allocator;
// Test case 1: Conflicting save and load
{
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "test_save.cgol"),
.load_file = try allocator.dupe(u8, "test_load.cgol"),
};
defer args.deinit(allocator);
try std.testing.expectError(cli.CliValidationError.ConflictingSaveLoad, cli.validateArgs(args));
}
// Test case 2: Empty save file
{
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, ""),
};
defer args.deinit(allocator);
try std.testing.expectError(cli.CliValidationError.InvalidSaveFile, cli.validateArgs(args));
}
// Test case 3: Zero auto-save interval
{
const args = cli.CliArgs{
.auto_save_every = 0,
};
try std.testing.expectError(cli.CliValidationError.InvalidAutoSaveInterval, cli.validateArgs(args));
}
// Test case 4: Save prefix without auto-save
{
var args = cli.CliArgs{
.save_prefix = try allocator.dupe(u8, "orphan_"),
};
defer args.deinit(allocator);
try std.testing.expectError(cli.CliValidationError.SavePrefixWithoutAutoSave, cli.validateArgs(args));
}
// Test case 5: Description without save operation
{
var args = cli.CliArgs{
.save_description = try allocator.dupe(u8, "Orphan description"),
};
defer args.deinit(allocator);
try std.testing.expectError(cli.CliValidationError.DescriptionWithoutSave, cli.validateArgs(args));
}
}
test "CLI integration - realistic usage scenarios" {
var allocator = std.testing.allocator;
// Scenario 1: Quick save during development
{
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "dev_checkpoint.cgol"),
.save_description = try allocator.dupe(u8, "Development checkpoint"),
.generations = 100,
};
defer args.deinit(allocator);
try cli.validateArgs(args);
}
// Scenario 2: Long-running simulation with auto-save
{
var args = cli.CliArgs{
.auto_save_every = 500,
.save_prefix = try allocator.dupe(u8, "long_sim_"),
.save_description = try allocator.dupe(u8, "Long simulation auto-backup"),
.generations = 10000,
.delay_ms = 50,
};
defer args.deinit(allocator);
try cli.validateArgs(args);
}
// Scenario 3: Pattern exploration with frequent saves
{
var args = cli.CliArgs{
.pattern_file = try allocator.dupe(u8, "patterns/gosperglidergun.rle"),
.auto_save_every = 50,
.save_prefix = try allocator.dupe(u8, "exploration_"),
.generations = 1000,
.rows = 50,
.cols = 80,
};
defer args.deinit(allocator);
try cli.validateArgs(args);
}
// Scenario 4: Research session with detailed saves
{
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "research_session_1.cgol"),
.save_description = try allocator.dupe(u8, "Research session #1 - oscillator behavior study"),
.auto_save_every = 200,
.save_prefix = try allocator.dupe(u8, "research_backup_"),
.pattern_file = try allocator.dupe(u8, "patterns/beacon.rle"),
.generations = 2000,
};
defer args.deinit(allocator);
try cli.validateArgs(args);
}
}
test "CLI integration - memory management for save parameters" {
var allocator = std.testing.allocator;
// Test that CliArgs properly manages memory for save-related strings
var args = cli.CliArgs{
.save_file = try allocator.dupe(u8, "memory_test.cgol"),
.save_description = try allocator.dupe(u8, "Memory management test"),
.save_prefix = try allocator.dupe(u8, "mem_test_"),
.pattern_file = try allocator.dupe(u8, "patterns/test.rle"),
.auto_save_every = 100,
};
// Verify all fields are allocated
try std.testing.expect(args.save_file != null);
try std.testing.expect(args.save_description != null);
try std.testing.expect(args.save_prefix != null);
try std.testing.expect(args.pattern_file != null);
try std.testing.expect(args.auto_save_every != null);
// Test validation works
try cli.validateArgs(args);
// Clean up - this should not leak memory
args.deinit(allocator);
}