MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / TestBlockRecordArray

Function TestBlockRecordArray

src/twtest/blockrecordarray_t.cpp:41–149  ·  view source on GitHub ↗

TODO: This test needs more comprehensive validity checks

Source from the content-addressed store, hash-verified

39
40//TODO: This test needs more comprehensive validity checks
41void TestBlockRecordArray()
42{
43 cDebug d("TestBlockRecordArray");
44
45 std::string fileName = TwTestPath("test2.bf");
46
47 cBlockFile bf;
48 bf.Open(fileName, 2, true); // opened up with two pages
49
50 // make sure the file is large enough...
51 //
52 while (bf.GetNumBlocks() < 2)
53 {
54 bf.CreateBlock();
55 }
56
57 // create the record arrays and associate them with the two blocks...
58 //
59 cBlockRecordArray ra1(&bf, 0);
60 ra1.InitNewBlock();
61 cBlockRecordArray ra2(&bf, 1);
62 ra2.InitNewBlock();
63
64 TEST(ra1.IsClassValid());
65 TEST(ra2.IsClassValid());
66
67 TEST(ra1.Initialized());
68
69 //
70 // now, start adding and removing things from the arrays...
71 //
72 static const char data1[] = "This is data 1";
73 static const char data2[] = "And here we have data 2";
74 static const char data3[] = "Here is d a t a 3!";
75 static const char data4[] = "Three cheers for data 4!";
76 ra1.AddItem((int8*)data1, sizeof(data1), 1);
77 // TEST(ra1.IsItemValid(1));
78 ra1.AddItem((int8*)data2, sizeof(data2), 2);
79 // TEST(ra1.IsItemValid(2));
80 ra1.AddItem((int8*)data3, sizeof(data3), 3);
81 // TEST(ra1.IsItemValid(3));
82 ra1.AddItem((int8*)data4, sizeof(data4), 4);
83 // TEST(ra1.IsItemValid(4));
84#ifdef _BLOCKFILE_DEBUG
85 ra1.TraceContents();
86#endif
87
88 // TODO -- try deleting the second to last and then the last thing from the array to
89 // see if we clean up properly.
90
91 // delete item 2...
92 ra1.DeleteItem(1);
93 TEST(!ra1.IsItemValid(1));
94#ifdef _BLOCKFILE_DEBUG
95 ra1.TraceContents();
96#endif
97
98 // add a new item...

Callers

nothing calls this directly

Calls 14

TwTestPathFunction · 0.85
GetNumBlocksMethod · 0.80
CreateBlockMethod · 0.80
InitNewBlockMethod · 0.80
IsClassValidMethod · 0.80
InitializedMethod · 0.80
DeleteItemMethod · 0.80
IsItemValidMethod · 0.80
InitForExistingBlockMethod · 0.80
TraceDebugMethod · 0.60
OpenMethod · 0.45
AddItemMethod · 0.45

Tested by

no test coverage detected