MCPcopy Create free account
hub / github.com/Kitware/VTK / TestBitArray

Function TestBitArray

Common/Core/Testing/Cxx/TestBitArray.cxx:16–105  ·  view source on GitHub ↗

This test makes sure that the unused reachable bits of the last byte are set to zero.

Source from the content-addressed store, hash-verified

14// This test makes sure that the unused reachable bits of the last byte are set
15// to zero.
16int TestBitArray(int, char*[])
17{
18 vtkNew<vtkBitArray> array;
19
20 array->SetNumberOfComponents(1);
21 array->SetNumberOfValues(1);
22
23 // [1]
24 array->SetValue(0, 1);
25 unsigned char* data = array->GetPointer(0);
26 std::string str = std::bitset<8>(data[0]).to_string();
27 if (str != "10000000")
28 {
29 std::cerr << "Bit array not initialized as expected. The raw data is " << str
30 << ", it should be 10000000" << std::endl;
31 return EXIT_FAILURE;
32 }
33
34 array->SetNumberOfValues(0);
35
36 // [1111 1011 | 101]
37 array->InsertValue(0, 1);
38 array->InsertNextValue(1);
39 array->InsertNextValue(1);
40 array->InsertNextValue(1);
41 array->InsertNextValue(1);
42 array->InsertNextValue(0);
43 array->InsertNextValue(1);
44 array->InsertNextValue(1);
45 array->InsertNextValue(1);
46 array->InsertNextValue(0);
47 array->InsertNextValue(1);
48
49 data = array->GetPointer(0);
50 str = std::bitset<8>(data[0]).to_string() + " " + std::bitset<8>(data[1]).to_string();
51 if (str != std::string("11111011 10100000"))
52 {
53 std::cerr << "Bit array not initialized as expected. The raw data is " << str
54 << ", it should be 11111011 10100000" << std::endl;
55 return EXIT_FAILURE;
56 }
57
58 unsigned char* ptr = array->WritePointer(0, 18);
59 // [1111 1011 | 1111 0011 | 10]
60 ptr[1] = 0xf3;
61 ptr[2] = (ptr[2] & 0x3f) | 0x80;
62 data = array->GetPointer(0);
63 str = std::bitset<8>(data[0]).to_string() + std::string(" ") +
64 std::bitset<8>(data[1]).to_string() + std::string(" ") + std::bitset<8>(data[2]).to_string();
65 if (str != "11111011 11110011 10000000")
66 {
67 std::cerr << "Bit array not initialized as expected. The raw data is " << str
68 << ", it should be 11111011 10110011 10000000" << std::endl;
69 return EXIT_FAILURE;
70 }
71
72 array->Resize(2);
73 data = array->GetPointer(0);

Callers

nothing calls this directly

Calls 12

to_stringMethod · 0.80
stringClass · 0.50
SetNumberOfComponentsMethod · 0.45
SetNumberOfValuesMethod · 0.45
SetValueMethod · 0.45
GetPointerMethod · 0.45
InsertValueMethod · 0.45
InsertNextValueMethod · 0.45
WritePointerMethod · 0.45
ResizeMethod · 0.45
ToIntMethod · 0.45
GetVariantValueMethod · 0.45

Tested by

no test coverage detected