1f049f87fSNicolas Bonnefon #include "gmock/gmock.h" 2f049f87fSNicolas Bonnefon 3f049f87fSNicolas Bonnefon #include "config.h" 4f049f87fSNicolas Bonnefon 5f049f87fSNicolas Bonnefon #include "log.h" 6f049f87fSNicolas Bonnefon 7f049f87fSNicolas Bonnefon #include "data/linepositionarray.h" 8f049f87fSNicolas Bonnefon 9f049f87fSNicolas Bonnefon using namespace std; 10f049f87fSNicolas Bonnefon using namespace testing; 11f049f87fSNicolas Bonnefon 12f049f87fSNicolas Bonnefon class LinePositionArraySmall: public testing::Test { 13f049f87fSNicolas Bonnefon public: 14f049f87fSNicolas Bonnefon LinePositionArray line_array; 15f049f87fSNicolas Bonnefon 16f049f87fSNicolas Bonnefon LinePositionArraySmall() { 17f049f87fSNicolas Bonnefon line_array.append( 4 ); 18f049f87fSNicolas Bonnefon line_array.append( 8 ); 19f049f87fSNicolas Bonnefon line_array.append( 10 ); 207a2f3a57SNicolas Bonnefon // A longer (>128) line 217a2f3a57SNicolas Bonnefon line_array.append( 345 ); 227a2f3a57SNicolas Bonnefon // An even longer (>16384) line 237a2f3a57SNicolas Bonnefon line_array.append( 20000 ); 247a2f3a57SNicolas Bonnefon // And a short one again 257a2f3a57SNicolas Bonnefon line_array.append( 20020 ); 26f049f87fSNicolas Bonnefon } 27f049f87fSNicolas Bonnefon }; 28f049f87fSNicolas Bonnefon 29f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, HasACorrectSize ) { 307a2f3a57SNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 6 ) ); 31f049f87fSNicolas Bonnefon } 32f049f87fSNicolas Bonnefon 33f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, RememberAddedLines ) { 34f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 35f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 36f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( 10 ) ); 377a2f3a57SNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( 345 ) ); 387a2f3a57SNicolas Bonnefon ASSERT_THAT( line_array[4], Eq( 20000 ) ); 397a2f3a57SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 20020 ) ); 40*6e2e573cSNicolas Bonnefon 41*6e2e573cSNicolas Bonnefon // This one again to eliminate caching effects 42*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( 345 ) ); 43f049f87fSNicolas Bonnefon } 44f049f87fSNicolas Bonnefon 45f049f87fSNicolas Bonnefon TEST_F( LinePositionArraySmall, FakeLFisNotKeptWhenAddingAfterIt ) { 46f049f87fSNicolas Bonnefon line_array.setFakeFinalLF(); 473c46a469SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 20020 ) ); 483c46a469SNicolas Bonnefon line_array.append( 20030 ); 493c46a469SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 20030 ) ); 50f049f87fSNicolas Bonnefon } 51f049f87fSNicolas Bonnefon 52f049f87fSNicolas Bonnefon class LinePositionArrayConcatOperation: public LinePositionArraySmall { 53f049f87fSNicolas Bonnefon public: 547151e3acSNicolas Bonnefon FastLinePositionArray other_array; 55f049f87fSNicolas Bonnefon 56f049f87fSNicolas Bonnefon LinePositionArrayConcatOperation() { 573c46a469SNicolas Bonnefon other_array.append( 150000 ); 583c46a469SNicolas Bonnefon other_array.append( 150023 ); 59f049f87fSNicolas Bonnefon } 60f049f87fSNicolas Bonnefon }; 61f049f87fSNicolas Bonnefon 62f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayConcatOperation, SimpleConcat ) { 637a2f3a57SNicolas Bonnefon line_array.append_list( other_array ); 64f049f87fSNicolas Bonnefon 653c46a469SNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 8 ) ); 66f049f87fSNicolas Bonnefon 67f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 68f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 693c46a469SNicolas Bonnefon 703c46a469SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 20020 ) ); 713c46a469SNicolas Bonnefon ASSERT_THAT( line_array[6], Eq( 150000 ) ); 723c46a469SNicolas Bonnefon ASSERT_THAT( line_array[7], Eq( 150023 ) ); 73f049f87fSNicolas Bonnefon } 74f049f87fSNicolas Bonnefon 75f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayConcatOperation, DoesNotKeepFakeLf ) { 76f049f87fSNicolas Bonnefon line_array.setFakeFinalLF(); 773c46a469SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 20020 ) ); 78f049f87fSNicolas Bonnefon 797a2f3a57SNicolas Bonnefon line_array.append_list( other_array ); 803c46a469SNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( 150000 ) ); 813c46a469SNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 7 ) ); 82f049f87fSNicolas Bonnefon } 83f049f87fSNicolas Bonnefon 843c46a469SNicolas Bonnefon class LinePositionArrayLong: public testing::Test { 853c46a469SNicolas Bonnefon public: 863c46a469SNicolas Bonnefon LinePositionArray line_array; 873c46a469SNicolas Bonnefon 883c46a469SNicolas Bonnefon LinePositionArrayLong() { 893c46a469SNicolas Bonnefon // Add 126 lines (of various sizes 903c46a469SNicolas Bonnefon for ( int i = 0; i < 127; i++ ) 913c46a469SNicolas Bonnefon line_array.append( i * 4 ); 923c46a469SNicolas Bonnefon // Line no 127 933c46a469SNicolas Bonnefon line_array.append( 514 ); 943c46a469SNicolas Bonnefon } 953c46a469SNicolas Bonnefon }; 963c46a469SNicolas Bonnefon 973c46a469SNicolas Bonnefon TEST_F( LinePositionArrayLong, LineNo128HasRightValue ) { 983c46a469SNicolas Bonnefon line_array.append( 524 ); 993c46a469SNicolas Bonnefon ASSERT_THAT( line_array[128], Eq( 524 ) ); 1003c46a469SNicolas Bonnefon } 1013c46a469SNicolas Bonnefon 1023c46a469SNicolas Bonnefon TEST_F( LinePositionArrayLong, FakeLFisNotKeptWhenAddingAfterIt ) { 1033c46a469SNicolas Bonnefon line_array.append( 524 ); 1043c46a469SNicolas Bonnefon line_array.setFakeFinalLF(); 1053c46a469SNicolas Bonnefon ASSERT_THAT( line_array[128], Eq( 524 ) ); 1063c46a469SNicolas Bonnefon line_array.append( 600 ); 1073c46a469SNicolas Bonnefon ASSERT_THAT( line_array[128], Eq( 600 ) ); 1083c46a469SNicolas Bonnefon } 1093c46a469SNicolas Bonnefon 1103c46a469SNicolas Bonnefon 111f049f87fSNicolas Bonnefon class LinePositionArrayBig: public testing::Test { 112f049f87fSNicolas Bonnefon public: 113f049f87fSNicolas Bonnefon LinePositionArray line_array; 114f049f87fSNicolas Bonnefon 115f049f87fSNicolas Bonnefon LinePositionArrayBig() { 116f049f87fSNicolas Bonnefon line_array.append( 4 ); 117f049f87fSNicolas Bonnefon line_array.append( 8 ); 118f049f87fSNicolas Bonnefon // A very big line 119f049f87fSNicolas Bonnefon line_array.append( UINT32_MAX - 10 ); 120*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) UINT32_MAX + 10LL ); 121*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) UINT32_MAX + 30LL ); 122*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) 2*UINT32_MAX ); 123*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) 2*UINT32_MAX + 10LL ); 124*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) 2*UINT32_MAX + 1000LL ); 125*6e2e573cSNicolas Bonnefon line_array.append( (uint64_t) 3*UINT32_MAX ); 126f049f87fSNicolas Bonnefon } 127f049f87fSNicolas Bonnefon }; 128f049f87fSNicolas Bonnefon 129f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBig, IsTheRightSize ) { 130*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array.size(), 9 ); 131f049f87fSNicolas Bonnefon } 132f049f87fSNicolas Bonnefon 133f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBig, HasRightData ) { 134f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 135f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 136f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( UINT32_MAX - 10 ) ); 137*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( (uint64_t) UINT32_MAX + 10LL ) ); 138*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[4], Eq( (uint64_t) UINT32_MAX + 30LL ) ); 139*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[5], Eq( (uint64_t) 2*UINT32_MAX ) ); 140*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[6], Eq( (uint64_t) 2*UINT32_MAX + 10LL ) ); 141*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[7], Eq( (uint64_t) 2*UINT32_MAX + 1000LL ) ); 142*6e2e573cSNicolas Bonnefon ASSERT_THAT( line_array[8], Eq( (uint64_t) 3*UINT32_MAX ) ); 143f049f87fSNicolas Bonnefon } 144f049f87fSNicolas Bonnefon 145f049f87fSNicolas Bonnefon class LinePositionArrayBigConcat: public testing::Test { 146f049f87fSNicolas Bonnefon public: 147f049f87fSNicolas Bonnefon LinePositionArray line_array; 1487151e3acSNicolas Bonnefon FastLinePositionArray other_array; 149f049f87fSNicolas Bonnefon 150f049f87fSNicolas Bonnefon LinePositionArrayBigConcat() { 151f049f87fSNicolas Bonnefon line_array.append( 4 ); 152f049f87fSNicolas Bonnefon line_array.append( 8 ); 153f049f87fSNicolas Bonnefon 154f049f87fSNicolas Bonnefon other_array.append( UINT32_MAX + 10 ); 155f049f87fSNicolas Bonnefon other_array.append( UINT32_MAX + 30 ); 156f049f87fSNicolas Bonnefon } 157f049f87fSNicolas Bonnefon }; 158f049f87fSNicolas Bonnefon 159f049f87fSNicolas Bonnefon TEST_F( LinePositionArrayBigConcat, SimpleBigConcat ) { 1607a2f3a57SNicolas Bonnefon line_array.append_list( other_array ); 161f049f87fSNicolas Bonnefon 162f049f87fSNicolas Bonnefon ASSERT_THAT( line_array.size(), Eq( 4 ) ); 163f049f87fSNicolas Bonnefon 164f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[0], Eq( 4 ) ); 165f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[1], Eq( 8 ) ); 166f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[2], Eq( UINT32_MAX + 10 ) ); 167f049f87fSNicolas Bonnefon ASSERT_THAT( line_array[3], Eq( UINT32_MAX + 30 ) ); 168f049f87fSNicolas Bonnefon } 169