Skip to content

Commit 6ba8027

Browse files
CodeRabbit Generated Unit Tests: Add ADLFile tests covering v1 to v3, offsets, and exceptions
1 parent f81f89e commit 6ba8027

File tree

1 file changed

+204
-0
lines changed
  • sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood

1 file changed

+204
-0
lines changed

sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/files/westwood/TestADLFile.cpp

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,210 @@ namespace HyperSonicDrivers::files::westwood
120120
}
121121
}
122122

123+
124+
namespace HyperSonicDrivers::files::westwood {
125+
126+
127+
/**
128+
129+
* Additional thorough tests for ADLFile.
130+
131+
* Framework: GoogleTest (gtest) with GoogleMock (gmock).
132+
133+
* Scope: Focus on public API and edge conditions seen across v1/v2/v3 fixtures.
134+
135+
*/
136+
137+
138+
139+
TEST(ADLFile, Version1_BoundaryIndicesAndOffsets) {
140+
141+
ADLFile f("../fixtures/EOBSOUND.ADL");
142+
143+
ASSERT_EQ(f.getVersion(), 1);
144+
145+
// Boundary: lowest and highest valid track index for reported offsets
146+
147+
const auto numTrackOffsets = f.getNumTrackOffsets();
148+
149+
ASSERT_GT(numTrackOffsets, 0);
150+
151+
const int firstIdx = 0;
152+
153+
const int lastIdx = static_cast<int>(numTrackOffsets) - 1;
154+
155+
// getTrack may map logical index to a program index; ensure it is within byte range
156+
157+
const int tFirst = f.getTrack(firstIdx);
158+
159+
const int tLast = f.getTrack(lastIdx);
160+
161+
EXPECT_GE(tFirst, 0);
162+
163+
EXPECT_GE(tLast, 0);
164+
165+
// Offsets should be within data size boundaries
166+
167+
const auto ds = f.getDataSize();
168+
169+
const auto offFirst = f.getTrackOffset(tFirst);
170+
171+
const auto offLast = f.getTrackOffset(tLast);
172+
173+
EXPECT_GE(offFirst, 0);
174+
175+
EXPECT_GE(offLast, 0);
176+
177+
EXPECT_LT(offFirst, ds);
178+
179+
EXPECT_LT(offLast, ds);
180+
181+
// Data pointer should be valid and readable at those offsets
182+
183+
const auto* data = f.getData();
184+
185+
ASSERT_NE(data, nullptr);
186+
187+
(void)data[offFirst];
188+
189+
(void)data[offLast];
190+
191+
}
192+
193+
194+
195+
TEST(ADLFile, Version2_SentinelAndConsistency) {
196+
197+
ADLFile f("../fixtures/DUNE19.ADL");
198+
199+
ASSERT_EQ(f.getVersion(), 2);
200+
201+
// Ensure that any sentinel (e.g., 0xFF) track entries yield consistent behavior:
202+
203+
// If a track entry equals 0xFF, instrument and track offset queries for that entry
204+
205+
// should not crash; depending on implementation they may throw or return a valid offset.
206+
207+
// We probe a range to find any sentinel occurrence and assert stable behavior.
208+
209+
const auto n = f.getNumTrackOffsets();
210+
211+
const auto* data = f.getData();
212+
213+
ASSERT_NE(data, nullptr);
214+
215+
bool foundSentinel = false;
216+
217+
for (int i = 0; i < static_cast<int>(n); ++i) {
218+
219+
int t = f.getTrack(i);
220+
221+
if (t == 0xFF) {
222+
223+
foundSentinel = true;
224+
225+
// For sentinel, just verify that program offset helpers do not UB: they may throw.
226+
227+
EXPECT_NO_FATAL_FAILURE({
228+
229+
try {
230+
231+
(void)f.getProgramOffset(t, ADLFile::PROG_TYPE::Track);
232+
233+
} catch (...) { /* acceptable: spec may throw */ }
234+
235+
});
236+
237+
EXPECT_NO_FATAL_FAILURE({
238+
239+
try {
240+
241+
(void)f.getProgramOffset(t, ADLFile::PROG_TYPE::Instrument);
242+
243+
} catch (...) { /* acceptable: spec may throw */ }
244+
245+
});
246+
247+
break;
248+
249+
}
250+
251+
}
252+
253+
SUCCEED() << "Sentinel presence in DUNE19.ADL: " << (foundSentinel ? "yes" : "no");
254+
255+
}
256+
257+
258+
259+
TEST(ADLFile, Version3_TrackAndInstrumentOffsetsAgreeWithProgramOffset) {
260+
261+
ADLFile f("../fixtures/LOREINTR.ADL");
262+
263+
ASSERT_EQ(f.getVersion(), 3);
264+
265+
const auto count = std::min<int>(static_cast<int>(f.getNumTrackOffsets()), 8);
266+
267+
// Cross-check first few entries to ensure getProgramOffset returns exactly
268+
269+
// the corresponding track/instrument offsets for both PROG_TYPE variants.
270+
271+
for (int i = 0; i < count; ++i) {
272+
273+
const int t = f.getTrack(i);
274+
275+
const auto to = f.getTrackOffset(t);
276+
277+
const auto io = f.getInstrumentOffset(t);
278+
279+
EXPECT_EQ(f.getProgramOffset(t, ADLFile::PROG_TYPE::Track), to) << "at logical index " << i;
280+
281+
EXPECT_EQ(f.getProgramOffset(t, ADLFile::PROG_TYPE::Instrument), io) << "at logical index " << i;
282+
283+
// Offsets must be strictly within [0, dataSize)
284+
285+
const auto ds = f.getDataSize();
286+
287+
EXPECT_GE(to, 0);
288+
289+
EXPECT_GE(io, 0);
290+
291+
EXPECT_LT(to, ds);
292+
293+
EXPECT_LT(io, ds);
294+
295+
}
296+
297+
}
298+
299+
300+
301+
TEST(ADLFile, Exceptions_OutOfRangeIndices) {
302+
303+
ADLFile f("../fixtures/EOBSOUND.ADL");
304+
305+
const int badIdx = static_cast<int>(f.getNumTrackOffsets()) + 100; // well beyond end
306+
307+
EXPECT_THROW(f.getTrack(badIdx), std::out_of_range);
308+
309+
EXPECT_THROW(f.getInstrumentOffset(badIdx), std::out_of_range);
310+
311+
}
312+
313+
314+
315+
TEST(ADLFile, Constructor_EmptyAndGarbagePaths) {
316+
317+
// Already have tests for empty string and argv[0]; add a garbage binary path.
318+
319+
EXPECT_THROW(ADLFile f("/this/path/does/not/exist.ADL"), std::system_error);
320+
321+
}
322+
323+
324+
325+
} // namespace HyperSonicDrivers::files::westwood
326+
123327
int main(int argc, char** argv)
124328
{
125329
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)