michael@0: // Copyright (c) 2010, Google Inc. michael@0: // All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions are michael@0: // met: michael@0: // michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above michael@0: // copyright notice, this list of conditions and the following disclaimer michael@0: // in the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google Inc. nor the names of its michael@0: // contributors may be used to endorse or promote products derived from michael@0: // this software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: michael@0: // Original author: Jim Blandy michael@0: michael@0: // test_assembler_unittest.cc: Unit tests for google_breakpad::TestAssembler. michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "breakpad_googletest_includes.h" michael@0: #include "common/test_assembler.h" michael@0: #include "common/using_std_string.h" michael@0: michael@0: using google_breakpad::test_assembler::Label; michael@0: using google_breakpad::test_assembler::Section; michael@0: using google_breakpad::test_assembler::kBigEndian; michael@0: using google_breakpad::test_assembler::kLittleEndian; michael@0: using testing::Test; michael@0: michael@0: TEST(ConstructLabel, Simple) { michael@0: Label l; michael@0: } michael@0: michael@0: TEST(ConstructLabel, Undefined) { michael@0: Label l; michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(ConstructLabelDeathTest, Undefined) { michael@0: Label l; michael@0: ASSERT_DEATH(l.Value(), "IsKnownConstant\\(&v\\)"); michael@0: } michael@0: michael@0: TEST(ConstructLabel, Constant) { michael@0: Label l(0x060b9f974eaf301eULL); michael@0: uint64_t v; michael@0: EXPECT_TRUE(l.IsKnownConstant(&v)); michael@0: EXPECT_EQ(v, 0x060b9f974eaf301eULL); michael@0: EXPECT_EQ(l.Value(), 0x060b9f974eaf301eULL); michael@0: } michael@0: michael@0: TEST(ConstructLabel, Copy) { michael@0: Label l; michael@0: Label m(l); michael@0: uint64_t v; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m, &v)); michael@0: EXPECT_EQ(0U, v); michael@0: } michael@0: michael@0: // The left-hand-side of a label assignment can be either michael@0: // unconstrained, related, or known. The right-hand-side can be any of michael@0: // those, or an integer. michael@0: TEST(Assignment, UnconstrainedToUnconstrained) { michael@0: Label l, m; michael@0: l = m; michael@0: EXPECT_EQ(0U, l-m); michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d)); michael@0: EXPECT_EQ(0U, d); michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Assignment, UnconstrainedToRelated) { michael@0: Label l, m, n; michael@0: l = n; michael@0: l = m; michael@0: EXPECT_EQ(0U, l-m); michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d)); michael@0: EXPECT_EQ(0U, d); michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Assignment, UnconstrainedToKnown) { michael@0: Label l, m; michael@0: l = 0x8fd16e55b20a39c1ULL; michael@0: l = m; michael@0: EXPECT_EQ(0U, l-m); michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d)); michael@0: EXPECT_EQ(0U, d); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x8fd16e55b20a39c1ULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, RelatedToUnconstrained) { michael@0: Label l, m, n; michael@0: m = n; michael@0: l = m; michael@0: EXPECT_EQ(0U, l-n); michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(n)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(n, &d)); michael@0: EXPECT_EQ(0U, d); michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Assignment, RelatedToRelated) { michael@0: Label l, m, n, o; michael@0: l = n; michael@0: m = o; michael@0: l = m; michael@0: EXPECT_EQ(0U, n-o); michael@0: EXPECT_TRUE(n.IsKnownOffsetFrom(o)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(n.IsKnownOffsetFrom(o, &d)); michael@0: EXPECT_EQ(0U, d); michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Assignment, RelatedToKnown) { michael@0: Label l, m, n; michael@0: m = n; michael@0: l = 0xd2011f8c82ad56f2ULL; michael@0: l = m; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0xd2011f8c82ad56f2ULL, l.Value()); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0xd2011f8c82ad56f2ULL, m.Value()); michael@0: EXPECT_TRUE(n.IsKnownConstant()); michael@0: EXPECT_EQ(0xd2011f8c82ad56f2ULL, n.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, KnownToUnconstrained) { michael@0: Label l, m; michael@0: m = 0x50b024c0d6073887ULL; michael@0: l = m; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0x50b024c0d6073887ULL, l.Value()); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x50b024c0d6073887ULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, KnownToRelated) { michael@0: Label l, m, n; michael@0: l = n; michael@0: m = 0x5348883655c727e5ULL; michael@0: l = m; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0x5348883655c727e5ULL, l.Value()); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x5348883655c727e5ULL, m.Value()); michael@0: EXPECT_TRUE(n.IsKnownConstant()); michael@0: EXPECT_EQ(0x5348883655c727e5ULL, n.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, KnownToKnown) { michael@0: Label l, m; michael@0: l = 0x36c209c20987564eULL; michael@0: m = 0x36c209c20987564eULL; michael@0: l = m; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0x36c209c20987564eULL, l.Value()); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x36c209c20987564eULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, ConstantToUnconstrained) { michael@0: Label l; michael@0: l = 0xc02495f4d7f5a957ULL; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0xc02495f4d7f5a957ULL, l.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, ConstantToRelated) { michael@0: Label l, m; michael@0: l = m; michael@0: l = 0x4577901cf275488dULL; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0x4577901cf275488dULL, l.Value()); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x4577901cf275488dULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Assignment, ConstantToKnown) { michael@0: Label l; michael@0: l = 0xec0b9c369b7e8ea7ULL; michael@0: l = 0xec0b9c369b7e8ea7ULL; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: EXPECT_EQ(0xec0b9c369b7e8ea7ULL, l.Value()); michael@0: } michael@0: michael@0: TEST(AssignmentDeathTest, Self) { michael@0: Label l; michael@0: ASSERT_DEATH(l = l, "binding != this"); michael@0: } michael@0: michael@0: TEST(AssignmentDeathTest, IndirectCycle) { michael@0: Label l, m, n; michael@0: l = m; michael@0: m = n; michael@0: ASSERT_DEATH(n = l, "binding != this"); michael@0: } michael@0: michael@0: TEST(AssignmentDeathTest, Cycle) { michael@0: Label l, m, n, o; michael@0: l = m; michael@0: m = n; michael@0: o = n; michael@0: ASSERT_DEATH(o = l, "binding != this"); michael@0: } michael@0: michael@0: TEST(Addition, LabelConstant) { michael@0: Label l, m; michael@0: m = l + 0x5248d93e8bbe9497ULL; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(0x5248d93e8bbe9497ULL, d); michael@0: EXPECT_FALSE(m.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Addition, ConstantLabel) { michael@0: Label l, m; michael@0: m = 0xf51e94e00d6e3c84ULL + l; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(0xf51e94e00d6e3c84ULL, d); michael@0: EXPECT_FALSE(m.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Addition, KnownLabelConstant) { michael@0: Label l, m; michael@0: l = 0x16286307042ce0d8ULL; michael@0: m = l + 0x3fdddd91306719d7ULL; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(0x3fdddd91306719d7ULL, d); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x16286307042ce0d8ULL + 0x3fdddd91306719d7ULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Addition, ConstantKnownLabel) { michael@0: Label l, m; michael@0: l = 0x50f62d0cdd1031deULL; michael@0: m = 0x1b13462d8577c538ULL + l; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(0x1b13462d8577c538ULL, d); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x50f62d0cdd1031deULL + 0x1b13462d8577c538ULL, m.Value()); michael@0: } michael@0: michael@0: TEST(Subtraction, LabelConstant) { michael@0: Label l, m; michael@0: m = l - 0x0620884d21d3138eULL; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(-0x0620884d21d3138eULL, d); michael@0: EXPECT_FALSE(m.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(Subtraction, KnownLabelConstant) { michael@0: Label l, m; michael@0: l = 0x6237fbaf9ef7929eULL; michael@0: m = l - 0x317730995d2ab6eeULL; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l)); michael@0: uint64_t d; michael@0: EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d)); michael@0: EXPECT_EQ(-0x317730995d2ab6eeULL, d); michael@0: EXPECT_TRUE(m.IsKnownConstant()); michael@0: EXPECT_EQ(0x6237fbaf9ef7929eULL - 0x317730995d2ab6eeULL, m.Value()); michael@0: } michael@0: michael@0: TEST(SubtractionDeathTest, LabelLabel) { michael@0: Label l, m; michael@0: ASSERT_DEATH(l - m, "IsKnownOffsetFrom\\(label, &offset\\)"); michael@0: } michael@0: michael@0: TEST(Subtraction, LabelLabel) { michael@0: Label l, m; michael@0: l = m + 0x7fa77ec63e28a17aULL; michael@0: EXPECT_EQ(0x7fa77ec63e28a17aULL, l - m); michael@0: EXPECT_EQ(-0x7fa77ec63e28a17aULL, m - l); michael@0: } michael@0: michael@0: TEST(IsKnownConstant, Undefined) { michael@0: Label l; michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(IsKnownConstant, RelatedLabel) { michael@0: Label l, m; michael@0: l = m; michael@0: EXPECT_FALSE(l.IsKnownConstant()); michael@0: EXPECT_FALSE(m.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(IsKnownConstant, Constant) { michael@0: Label l; michael@0: l = 0xf374b1bdd6a22576ULL; michael@0: EXPECT_TRUE(l.IsKnownConstant()); michael@0: } michael@0: michael@0: TEST(IsKnownOffsetFrom, Unrelated) { michael@0: Label l, m; michael@0: EXPECT_FALSE(l.IsKnownOffsetFrom(m)); michael@0: } michael@0: michael@0: TEST(IsKnownOffsetFrom, Related) { michael@0: Label l, m; michael@0: l = m; michael@0: EXPECT_TRUE(l.IsKnownOffsetFrom(m)); michael@0: } michael@0: michael@0: // Test the construction of chains of related labels, and the michael@0: // propagation of values through them. michael@0: // michael@0: // Although the relations between labels are supposed to behave michael@0: // symmetrically --- that is, 'a = b' should put a and b in michael@0: // indistinguishable states --- there's a distinction made internally michael@0: // between the target (a) and the source (b). michael@0: // michael@0: // So there are five test axes to cover: michael@0: // michael@0: // - Do we construct the chain with assignment ("Assign") or with constructors michael@0: // ("Construct")? michael@0: // michael@0: // - Do we set the value of the label at the start of the chain michael@0: // ("Start") or the label at the end ("End")? michael@0: // michael@0: // - Are we testing the propagation of a relationship between variable michael@0: // values ("Relation"), or the propagation of a known constant value michael@0: // ("Value")? michael@0: // michael@0: // - Do we set the value before building the chain ("Before") or after michael@0: // the chain has been built ("After")? michael@0: // michael@0: // - Do we add new relationships to the end of the existing chain michael@0: // ("Forward") or to the beginning ("Backward")? michael@0: // michael@0: // Of course, "Construct" and "Backward" can't be combined, which michael@0: // eliminates eight combinations, and "Construct", "End", and "Before" michael@0: // can't be combined, which eliminates two more, so there are are 22 michael@0: // combinations, not 32. michael@0: michael@0: TEST(LabelChain, AssignStartRelationBeforeForward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: a = x; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartRelationBeforeBackward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: a = x; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartRelationAfterForward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: a = x; michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartRelationAfterBackward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: a = x; michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartValueBeforeForward) { michael@0: Label a, b, c, d; michael@0: a = 0xa131200190546ac2ULL; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: EXPECT_EQ(0xa131200190546ac2ULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL + 0x11U, c.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL + 0x1U, b.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL + 0U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartValueBeforeBackward) { michael@0: Label a, b, c, d; michael@0: a = 0x8da17e1670ad4fa2ULL; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x11U, c.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x1U, b.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartValueAfterForward) { michael@0: Label a, b, c, d; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: a = 0x99b8f51bafd41adaULL; michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL + 0x11U, c.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL + 0x1U, b.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL + 0U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignStartValueAfterBackward) { michael@0: Label a, b, c, d; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: a = 0xc86ca1d97ab5df6eULL; michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x11U, c.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x1U, b.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndRelationBeforeForward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: x = d; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: EXPECT_EQ(-(uint64_t)0x111U, a-x); michael@0: EXPECT_EQ(-(uint64_t)0x110U, b-x); michael@0: EXPECT_EQ(-(uint64_t)0x100U, c-x); michael@0: EXPECT_EQ(-(uint64_t)0U, d-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndRelationBeforeBackward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: x = d; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: EXPECT_EQ(-(uint64_t)0x111U, a-x); michael@0: EXPECT_EQ(-(uint64_t)0x110U, b-x); michael@0: EXPECT_EQ(-(uint64_t)0x100U, c-x); michael@0: EXPECT_EQ(-(uint64_t)0U, d-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndRelationAfterForward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: x = d; michael@0: EXPECT_EQ(-(uint64_t)0x111U, a-x); michael@0: EXPECT_EQ(-(uint64_t)0x110U, b-x); michael@0: EXPECT_EQ(-(uint64_t)0x100U, c-x); michael@0: EXPECT_EQ(-(uint64_t)0x000U, d-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndRelationAfterBackward) { michael@0: Label a, b, c, d; michael@0: Label x; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: x = d; michael@0: EXPECT_EQ(-(uint64_t)0x111U, a-x); michael@0: EXPECT_EQ(-(uint64_t)0x110U, b-x); michael@0: EXPECT_EQ(-(uint64_t)0x100U, c-x); michael@0: EXPECT_EQ(-(uint64_t)0x000U, d-x); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndValueBeforeForward) { michael@0: Label a, b, c, d; michael@0: d = 0xa131200190546ac2ULL; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: EXPECT_EQ(0xa131200190546ac2ULL - 0x111, a.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL - 0x110, b.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL - 0x100, c.Value()); michael@0: EXPECT_EQ(0xa131200190546ac2ULL - 0x000, d.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndValueBeforeBackward) { michael@0: Label a, b, c, d; michael@0: d = 0x8da17e1670ad4fa2ULL; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x111, a.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x110, b.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x100, c.Value()); michael@0: EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x000, d.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndValueAfterForward) { michael@0: Label a, b, c, d; michael@0: b = a + 0x1; michael@0: c = b + 0x10; michael@0: d = c + 0x100; michael@0: d = 0x99b8f51bafd41adaULL; michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x111, a.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x110, b.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x100, c.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x000, d.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, AssignEndValueAfterBackward) { michael@0: Label a, b, c, d; michael@0: d = c + 0x100; michael@0: c = b + 0x10; michael@0: b = a + 0x1; michael@0: d = 0xc86ca1d97ab5df6eULL; michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x111, a.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x110, b.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x100, c.Value()); michael@0: EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x000, d.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructStartRelationBeforeForward) { michael@0: Label x; michael@0: Label a(x); michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructStartRelationAfterForward) { michael@0: Label x; michael@0: Label a; michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: a = x; michael@0: EXPECT_EQ(0x111U, d-x); michael@0: EXPECT_EQ(0x11U, c-x); michael@0: EXPECT_EQ(0x1U, b-x); michael@0: EXPECT_EQ(0U, a-x); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructStartValueBeforeForward) { michael@0: Label a(0x5d234d177d01ccc8ULL); michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x011U, c.Value()); michael@0: EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x001U, b.Value()); michael@0: EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x000U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructStartValueAfterForward) { michael@0: Label a; michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: a = 0xded85d54586e84fcULL; michael@0: EXPECT_EQ(0xded85d54586e84fcULL + 0x111U, d.Value()); michael@0: EXPECT_EQ(0xded85d54586e84fcULL + 0x011U, c.Value()); michael@0: EXPECT_EQ(0xded85d54586e84fcULL + 0x001U, b.Value()); michael@0: EXPECT_EQ(0xded85d54586e84fcULL + 0x000U, a.Value()); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructEndRelationAfterForward) { michael@0: Label x; michael@0: Label a; michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: x = d; michael@0: EXPECT_EQ(-(uint64_t)0x111U, a-x); michael@0: EXPECT_EQ(-(uint64_t)0x110U, b-x); michael@0: EXPECT_EQ(-(uint64_t)0x100U, c-x); michael@0: EXPECT_EQ(-(uint64_t)0x000U, d-x); michael@0: } michael@0: michael@0: TEST(LabelChain, ConstructEndValueAfterForward) { michael@0: Label a; michael@0: Label b(a + 0x1); michael@0: Label c(b + 0x10); michael@0: Label d(c + 0x100); michael@0: d = 0x99b8f51bafd41adaULL; michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x111, a.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x110, b.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x100, c.Value()); michael@0: EXPECT_EQ(0x99b8f51bafd41adaULL - 0x000, d.Value()); michael@0: } michael@0: michael@0: TEST(LabelTree, KnownValue) { michael@0: Label l, m, n, o, p; michael@0: l = m; michael@0: m = n; michael@0: o = p; michael@0: p = n; michael@0: l = 0x536b5de3d468a1b5ULL; michael@0: EXPECT_EQ(0x536b5de3d468a1b5ULL, o.Value()); michael@0: } michael@0: michael@0: TEST(LabelTree, Related) { michael@0: Label l, m, n, o, p; michael@0: l = m - 1; michael@0: m = n - 10; michael@0: o = p + 100; michael@0: p = n + 1000; michael@0: EXPECT_EQ(1111U, o - l); michael@0: } michael@0: michael@0: TEST(EquationDeathTest, EqualConstants) { michael@0: Label m = 0x0d3962f280f07d24ULL; michael@0: Label n = 0x0d3962f280f07d24ULL; michael@0: m = n; // no death expected michael@0: } michael@0: michael@0: TEST(EquationDeathTest, EqualIndirectConstants) { michael@0: Label m = 0xa347f1e5238fe6a1ULL; michael@0: Label n; michael@0: Label o = n; michael@0: n = 0xa347f1e5238fe6a1ULL; michael@0: n = m; // no death expected michael@0: } michael@0: michael@0: TEST(EquationDeathTest, ConstantClash) { michael@0: Label m = 0xd4cc0f4f630ec741ULL; michael@0: Label n = 0x934cd2d8254fc3eaULL; michael@0: ASSERT_DEATH(m = n, "addend_ == addend"); michael@0: } michael@0: michael@0: TEST(EquationDeathTest, IndirectConstantClash) { michael@0: Label m = 0xd4cc0f4f630ec741ULL; michael@0: Label n, o; michael@0: n = o; michael@0: o = 0xcfbe3b83ac49ce86ULL; michael@0: ASSERT_DEATH(m = n, "addend_ == addend"); michael@0: } michael@0: michael@0: // Assigning to a related label may free the next Binding on its michael@0: // chain. This test always passes; it is interesting to memory michael@0: // checkers and coverage analysis. michael@0: TEST(LabelReferenceCount, AssignmentFree) { michael@0: Label l; michael@0: { michael@0: Label m; michael@0: l = m; michael@0: } michael@0: // This should free m's Binding. michael@0: l = 0xca8bae92f0376d4fULL; michael@0: ASSERT_EQ(0xca8bae92f0376d4fULL, l.Value()); michael@0: } michael@0: michael@0: // Finding the value of a label may free the Binding it refers to. This test michael@0: // always passes; it is interesting to memory checkers and coverage analysis. michael@0: TEST(LabelReferenceCount, FindValueFree) { michael@0: Label l; michael@0: { michael@0: Label m, n; michael@0: l = m; michael@0: m = n; michael@0: n = 0x7a0b0c576672daafULL; michael@0: // At this point, l's Binding refers to m's Binding, which refers michael@0: // to n's binding. michael@0: } michael@0: // Now, l is the only reference keeping the three Bindings alive. michael@0: // Resolving its value should free l's and m's original bindings. michael@0: ASSERT_EQ(0x7a0b0c576672daafULL, l.Value()); michael@0: } michael@0: michael@0: TEST(ConstructSection, Simple) { michael@0: Section s; michael@0: } michael@0: michael@0: TEST(ConstructSection, WithEndian) { michael@0: Section s(kBigEndian); michael@0: } michael@0: michael@0: // A fixture class for TestAssembler::Section tests. michael@0: class SectionFixture { michael@0: public: michael@0: Section section; michael@0: string contents; michael@0: static const uint8_t data[]; michael@0: static const size_t data_size; michael@0: }; michael@0: michael@0: const uint8_t SectionFixture::data[] = { michael@0: 0x87, 0x4f, 0x43, 0x67, 0x30, 0xd0, 0xd4, 0x0e michael@0: }; michael@0: michael@0: #define I0() michael@0: #define I1(a) { a } michael@0: #define I2(a,b) { a,b } michael@0: #define I3(a,b,c) { a,b,c } michael@0: #define I4(a,b,c,d) { a,b,c,d } michael@0: #define I5(a,b,c,d,e) { a,b,c,d,e } michael@0: #define I6(a,b,c,d,e,f) { a,b,c,d,e,f } michael@0: #define I7(a,b,c,d,e,f,g) { a,b,c,d,e,f,g } michael@0: #define I8(a,b,c,d,e,f,g,h) { a,b,c,d,e,f,g,h } michael@0: #define I9(a,b,c,d,e,f,g,h,i) { a,b,c,d,e,f,g,h,i } michael@0: #define ASSERT_BYTES(s, b) \ michael@0: do \ michael@0: { \ michael@0: static const uint8_t expected_bytes[] = b; \ michael@0: ASSERT_EQ(sizeof(expected_bytes), s.size()); \ michael@0: ASSERT_TRUE(memcmp(s.data(), (const char *) expected_bytes, \ michael@0: sizeof(expected_bytes)) == 0); \ michael@0: } \ michael@0: while(0) michael@0: michael@0: class Append: public SectionFixture, public Test { }; michael@0: michael@0: TEST_F(Append, Bytes) { michael@0: section.Append(data, sizeof(data)); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_EQ(sizeof(data), contents.size()); michael@0: EXPECT_TRUE(0 == memcmp(contents.data(), (const char *) data, sizeof(data))); michael@0: } michael@0: michael@0: TEST_F(Append, BytesTwice) { michael@0: section.Append(data, sizeof(data)); michael@0: section.Append(data, sizeof(data)); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_EQ(2 * sizeof(data), contents.size()); michael@0: ASSERT_TRUE(0 == memcmp(contents.data(), (const char *) data, sizeof(data))); michael@0: ASSERT_TRUE(0 == memcmp(contents.data() + sizeof(data), michael@0: (const char *) data, sizeof(data))); michael@0: } michael@0: michael@0: TEST_F(Append, String) { michael@0: string s1 = "howdy "; michael@0: string s2 = "there"; michael@0: section.Append(s1); michael@0: section.Append(s2); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_STREQ(contents.c_str(), "howdy there"); michael@0: } michael@0: michael@0: TEST_F(Append, CString) { michael@0: section.AppendCString("howdy"); michael@0: section.AppendCString(""); michael@0: section.AppendCString("there"); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_EQ(string("howdy\0\0there\0", 13), contents); michael@0: } michael@0: michael@0: TEST_F(Append, CStringSize) { michael@0: section.AppendCString("howdy", 3); michael@0: section.AppendCString("there", 5); michael@0: section.AppendCString("fred", 6); michael@0: section.AppendCString("natalie", 0); michael@0: section.AppendCString("", 10); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_EQ(string("howtherefred\0\0\0\0\0\0\0\0\0\0\0\0", 24), contents); michael@0: } michael@0: michael@0: TEST_F(Append, RepeatedBytes) { michael@0: section.Append((size_t) 10, '*'); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_STREQ(contents.c_str(), "**********"); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE1) { michael@0: section.Append(kLittleEndian, 1, 42); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I1(42)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE2) { michael@0: section.Append(kLittleEndian, 2, 0x15a1); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0xa1, 0x15)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE3) { michael@0: section.Append(kLittleEndian, 3, 0x59ae8d); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x8d, 0xae, 0x59)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE4) { michael@0: section.Append(kLittleEndian, 4, 0x51603c56); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I4(0x56, 0x3c, 0x60, 0x51)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE5) { michael@0: section.Append(kLittleEndian, 5, 0x385e2803b4ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0xb4, 0x03, 0x28, 0x5e, 0x38)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE6) { michael@0: section.Append(kLittleEndian, 6, 0xc7db9534dd1fULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I6(0x1f, 0xdd, 0x34, 0x95, 0xdb, 0xc7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE7) { michael@0: section.Append(kLittleEndian, 7, 0x1445c9f1b843e6ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I7(0xe6, 0x43, 0xb8, 0xf1, 0xc9, 0x45, 0x14)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE8) { michael@0: section.Append(kLittleEndian, 8, 0xaf48019dfe5c01e5ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I8(0xe5, 0x01, 0x5c, 0xfe, 0x9d, 0x01, 0x48, 0xaf)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE1) { michael@0: section.Append(kBigEndian, 1, 0xd0ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I1(0xd0)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE2) { michael@0: section.Append(kBigEndian, 2, 0x2e7eULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2e, 0x7e)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE3) { michael@0: section.Append(kBigEndian, 3, 0x37dad6ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x37, 0xda, 0xd6)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE4) { michael@0: section.Append(kBigEndian, 4, 0x715935c7ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I4(0x71, 0x59, 0x35, 0xc7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE5) { michael@0: section.Append(kBigEndian, 5, 0x42baeb02b7ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x42, 0xba, 0xeb, 0x02, 0xb7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE6) { michael@0: section.Append(kBigEndian, 6, 0xf1cdf10e7b18ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I6(0xf1, 0xcd, 0xf1, 0x0e, 0x7b, 0x18)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE7) { michael@0: section.Append(kBigEndian, 7, 0xf50a724f0b0d20ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I7(0xf5, 0x0a, 0x72, 0x4f, 0x0b, 0x0d, 0x20)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE8) { michael@0: section.Append(kBigEndian, 8, 0xa6b2cb5e98dc9c16ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I8(0xa6, 0xb2, 0xcb, 0x5e, 0x98, 0xdc, 0x9c, 0x16)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE1Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 1, l); michael@0: l = 42; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I1(42)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE2Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 2, l); michael@0: l = 0x15a1; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0xa1, 0x15)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE3Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 3, l); michael@0: l = 0x59ae8d; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x8d, 0xae, 0x59)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE4Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 4, l); michael@0: l = 0x51603c56; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I4(0x56, 0x3c, 0x60, 0x51)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE5Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 5, l); michael@0: l = 0x385e2803b4ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0xb4, 0x03, 0x28, 0x5e, 0x38)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE6Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 6, l); michael@0: l = 0xc7db9534dd1fULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I6(0x1f, 0xdd, 0x34, 0x95, 0xdb, 0xc7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE7Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 7, l); michael@0: l = 0x1445c9f1b843e6ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I7(0xe6, 0x43, 0xb8, 0xf1, 0xc9, 0x45, 0x14)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralLE8Label) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 8, l); michael@0: l = 0xaf48019dfe5c01e5ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I8(0xe5, 0x01, 0x5c, 0xfe, 0x9d, 0x01, 0x48, 0xaf)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE1Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 1, l); michael@0: l = 0xd0ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I1(0xd0)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE2Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 2, l); michael@0: l = 0x2e7eULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2e, 0x7e)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE3Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 3, l); michael@0: l = 0x37dad6ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x37, 0xda, 0xd6)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE4Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 4, l); michael@0: l = 0x715935c7ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I4(0x71, 0x59, 0x35, 0xc7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE5Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 5, l); michael@0: l = 0x42baeb02b7ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x42, 0xba, 0xeb, 0x02, 0xb7)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE6Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 6, l); michael@0: l = 0xf1cdf10e7b18ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I6(0xf1, 0xcd, 0xf1, 0x0e, 0x7b, 0x18)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE7Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 7, l); michael@0: l = 0xf50a724f0b0d20ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I7(0xf5, 0x0a, 0x72, 0x4f, 0x0b, 0x0d, 0x20)); michael@0: } michael@0: michael@0: TEST_F(Append, GeneralBE8Label) { michael@0: Label l; michael@0: section.Append(kBigEndian, 8, l); michael@0: l = 0xa6b2cb5e98dc9c16ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I8(0xa6, 0xb2, 0xcb, 0x5e, 0x98, 0xdc, 0x9c, 0x16)); michael@0: } michael@0: michael@0: TEST_F(Append, B8) { michael@0: section.Append(1, 0x2a); michael@0: section.B8(0xd3U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0xd3)); michael@0: } michael@0: michael@0: TEST_F(Append, B8Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.B8(l); michael@0: l = 0x4bU; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0x4b)); michael@0: } michael@0: michael@0: TEST_F(Append, B16) { michael@0: section.Append(1, 0x2a); michael@0: section.B16(0x472aU); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x47, 0x2a)); michael@0: } michael@0: michael@0: TEST_F(Append, B16Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.B16(l); michael@0: l = 0x55e8U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x55, 0xe8)); michael@0: } michael@0: michael@0: TEST_F(Append, B32) { michael@0: section.Append(1, 0x2a); michael@0: section.B32(0xbd412cbcU); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0xbd, 0x41, 0x2c, 0xbc)); michael@0: } michael@0: michael@0: TEST_F(Append, B32Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.B32(l); michael@0: l = 0x208e37d5U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0x20, 0x8e, 0x37, 0xd5)); michael@0: } michael@0: michael@0: TEST_F(Append, B64) { michael@0: section.Append(1, 0x2a); michael@0: section.B64(0x3402a013111e68adULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0x34, 0x02, 0xa0, 0x13, 0x11, 0x1e, 0x68, 0xad)); michael@0: } michael@0: michael@0: TEST_F(Append, B64Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.B64(l); michael@0: l = 0x355dbfbb4ac6d57fULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0x35, 0x5d, 0xbf, 0xbb, 0x4a, 0xc6, 0xd5, 0x7f)); michael@0: } michael@0: michael@0: TEST_F(Append, L8) { michael@0: section.Append(1, 0x2a); michael@0: section.L8(0x26U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0x26)); michael@0: } michael@0: michael@0: TEST_F(Append, L8Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.L8(l); michael@0: l = 0xa8U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0xa8)); michael@0: } michael@0: michael@0: TEST_F(Append, L16) { michael@0: section.Append(1, 0x2a); michael@0: section.L16(0xca6dU); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x6d, 0xca)); michael@0: } michael@0: michael@0: TEST_F(Append, L16Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.L16(l); michael@0: l = 0xd21fU; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x1f, 0xd2)); michael@0: } michael@0: michael@0: TEST_F(Append, L32) { michael@0: section.Append(1, 0x2a); michael@0: section.L32(0x558f6181U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0x81, 0x61, 0x8f, 0x55)); michael@0: } michael@0: michael@0: TEST_F(Append, L32Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.L32(l); michael@0: l = 0x4b810f82U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0x82, 0x0f, 0x81, 0x4b)); michael@0: } michael@0: michael@0: TEST_F(Append, L64) { michael@0: section.Append(1, 0x2a); michael@0: section.L64(0x564384f7579515bfULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0xbf, 0x15, 0x95, 0x57, 0xf7, 0x84, 0x43, 0x56)); michael@0: } michael@0: michael@0: TEST_F(Append, L64Label) { michael@0: Label l; michael@0: section.Append(1, 0x2a); michael@0: section.L64(l); michael@0: l = 0x424b1d020667c8dbULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0xdb, 0xc8, 0x67, 0x06, 0x02, 0x1d, 0x4b, 0x42)); michael@0: } michael@0: michael@0: TEST_F(Append, D8Big) { michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D8(0xe6U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0xe6)); michael@0: } michael@0: michael@0: TEST_F(Append, D8BigLabel) { michael@0: Label l; michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D8(l); michael@0: l = 0xeeU; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0xee)); michael@0: } michael@0: michael@0: TEST_F(Append, D16Big) { michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D16(0x83b1U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x83, 0xb1)); michael@0: } michael@0: michael@0: TEST_F(Append, D16BigLabel) { michael@0: Label l; michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D16(l); michael@0: l = 0x5b55U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x5b, 0x55)); michael@0: } michael@0: michael@0: TEST_F(Append, D32Big) { michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D32(0xd0b0e431U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0xd0, 0xb0, 0xe4, 0x31)); michael@0: } michael@0: michael@0: TEST_F(Append, D32BigLabel) { michael@0: Label l; michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D32(l); michael@0: l = 0x312fb340U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0x31, 0x2f, 0xb3, 0x40)); michael@0: } michael@0: michael@0: TEST_F(Append, D64Big) { michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D64(0xb109843500dbcb16ULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0xb1, 0x09, 0x84, 0x35, 0x00, 0xdb, 0xcb, 0x16)); michael@0: } michael@0: michael@0: TEST_F(Append, D64BigLabel) { michael@0: Label l; michael@0: section.set_endianness(kBigEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D64(l); michael@0: l = 0x9a0d61b70f671fd7ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0x9a, 0x0d, 0x61, 0xb7, 0x0f, 0x67, 0x1f, 0xd7)); michael@0: } michael@0: michael@0: TEST_F(Append, D8Little) { michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D8(0x42U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0x42)); michael@0: } michael@0: michael@0: TEST_F(Append, D8LittleLabel) { michael@0: Label l; michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D8(l); michael@0: l = 0x05U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I2(0x2a, 0x05)); michael@0: } michael@0: michael@0: TEST_F(Append, D16Little) { michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D16(0xc5c5U); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0xc5, 0xc5)); michael@0: } michael@0: michael@0: TEST_F(Append, D16LittleLabel) { michael@0: Label l; michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D16(l); michael@0: l = 0xb620U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I3(0x2a, 0x20, 0xb6)); michael@0: } michael@0: michael@0: TEST_F(Append, D32Little) { michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D32(0x1a87d0feU); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0xfe, 0xd0, 0x87, 0x1a)); michael@0: } michael@0: michael@0: TEST_F(Append, D32LittleLabel) { michael@0: Label l; michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D32(l); michael@0: l = 0xb8012d6bU; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I5(0x2a, 0x6b, 0x2d, 0x01, 0xb8)); michael@0: } michael@0: michael@0: TEST_F(Append, D64Little) { michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D64(0x42de75c61375a1deULL); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0xde, 0xa1, 0x75, 0x13, 0xc6, 0x75, 0xde, 0x42)); michael@0: } michael@0: michael@0: TEST_F(Append, D64LittleLabel) { michael@0: Label l; michael@0: section.set_endianness(kLittleEndian); michael@0: section.Append(1, 0x2a); michael@0: section.D64(l); michael@0: l = 0x8b3bececf3fb5312ULL; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, michael@0: I9(0x2a, 0x12, 0x53, 0xfb, 0xf3, 0xec, 0xec, 0x3b, 0x8b)); michael@0: } michael@0: michael@0: TEST_F(Append, Variety) { michael@0: Label a, b, c, d, e, f, g, h; michael@0: section.Append(kBigEndian, 1, a) michael@0: .Append(kLittleEndian, 8, h) michael@0: .Append(kBigEndian, 1, 0x8bULL) michael@0: .Append(kLittleEndian, 8, 0x0ea56540448f4439ULL) michael@0: .Append(kBigEndian, 2, b) michael@0: .Append(kLittleEndian, 7, g) michael@0: .Append(kBigEndian, 2, 0xcf15ULL) michael@0: .Append(kLittleEndian, 7, 0x29694f04c5724aULL) michael@0: .Append(kBigEndian, 3, c) michael@0: .Append(kLittleEndian, 6, f) michael@0: .Append(kBigEndian, 3, 0x8c3ffdULL) michael@0: .Append(kLittleEndian, 6, 0x6f11ba80187aULL) michael@0: .Append(kBigEndian, 4, d) michael@0: .Append(kLittleEndian, 5, e) michael@0: .Append(kBigEndian, 4, 0x2fda2472ULL) michael@0: .Append(kLittleEndian, 5, 0x0aa02d423fULL) michael@0: .Append(kBigEndian, 5, e) michael@0: .Append(kLittleEndian, 4, d) michael@0: .Append(kBigEndian, 5, 0x53ba432138ULL) michael@0: .Append(kLittleEndian, 4, 0xf139ae60ULL) michael@0: .Append(kBigEndian, 6, f) michael@0: .Append(kLittleEndian, 3, c) michael@0: .Append(kBigEndian, 6, 0x168e436af716ULL) michael@0: .Append(kLittleEndian, 3, 0x3ef189ULL) michael@0: .Append(kBigEndian, 7, g) michael@0: .Append(kLittleEndian, 2, b) michael@0: .Append(kBigEndian, 7, 0xacd4ef233e47d9ULL) michael@0: .Append(kLittleEndian, 2, 0x5311ULL) michael@0: .Append(kBigEndian, 8, h) michael@0: .Append(kLittleEndian, 1, a) michael@0: .Append(kBigEndian, 8, 0x4668d5f1c93637a1ULL) michael@0: .Append(kLittleEndian, 1, 0x65ULL); michael@0: a = 0x79ac9bd8aa256b35ULL; michael@0: b = 0x22d13097ef86c91cULL; michael@0: c = 0xf204968b0a05862fULL; michael@0: d = 0x163177f15a0eb4ecULL; michael@0: e = 0xbd1b0f1d977f2246ULL; michael@0: f = 0x2b0842eee83c6461ULL; michael@0: g = 0x92f4b928a4bf875eULL; michael@0: h = 0x61a199a8f7286ba6ULL; michael@0: ASSERT_EQ(8 * 18U, section.Size()); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: michael@0: static const uint8_t expected[] = { michael@0: 0x35, 0xa6, 0x6b, 0x28, 0xf7, 0xa8, 0x99, 0xa1, 0x61, michael@0: 0x8b, 0x39, 0x44, 0x8f, 0x44, 0x40, 0x65, 0xa5, 0x0e, michael@0: 0xc9, 0x1c, 0x5e, 0x87, 0xbf, 0xa4, 0x28, 0xb9, 0xf4, michael@0: 0xcf, 0x15, 0x4a, 0x72, 0xc5, 0x04, 0x4f, 0x69, 0x29, michael@0: 0x05, 0x86, 0x2f, 0x61, 0x64, 0x3c, 0xe8, 0xee, 0x42, michael@0: 0x8c, 0x3f, 0xfd, 0x7a, 0x18, 0x80, 0xba, 0x11, 0x6f, michael@0: 0x5a, 0x0e, 0xb4, 0xec, 0x46, 0x22, 0x7f, 0x97, 0x1d, michael@0: 0x2f, 0xda, 0x24, 0x72, 0x3f, 0x42, 0x2d, 0xa0, 0x0a, michael@0: 0x1d, 0x97, 0x7f, 0x22, 0x46, 0xec, 0xb4, 0x0e, 0x5a, michael@0: 0x53, 0xba, 0x43, 0x21, 0x38, 0x60, 0xae, 0x39, 0xf1, michael@0: 0x42, 0xee, 0xe8, 0x3c, 0x64, 0x61, 0x2f, 0x86, 0x05, michael@0: 0x16, 0x8e, 0x43, 0x6a, 0xf7, 0x16, 0x89, 0xf1, 0x3e, michael@0: 0xf4, 0xb9, 0x28, 0xa4, 0xbf, 0x87, 0x5e, 0x1c, 0xc9, michael@0: 0xac, 0xd4, 0xef, 0x23, 0x3e, 0x47, 0xd9, 0x11, 0x53, michael@0: 0x61, 0xa1, 0x99, 0xa8, 0xf7, 0x28, 0x6b, 0xa6, 0x35, michael@0: 0x46, 0x68, 0xd5, 0xf1, 0xc9, 0x36, 0x37, 0xa1, 0x65, michael@0: }; michael@0: michael@0: ASSERT_TRUE(0 == memcmp(contents.data(), expected, sizeof(expected))); michael@0: } michael@0: michael@0: TEST_F(Append, Section) { michael@0: section.Append("murder"); michael@0: { michael@0: Section middle; michael@0: middle.Append(" she"); michael@0: section.Append(middle); michael@0: } michael@0: section.Append(" wrote"); michael@0: EXPECT_EQ(16U, section.Size()); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_STREQ(contents.c_str(), "murder she wrote"); michael@0: } michael@0: michael@0: TEST_F(Append, SectionRefs) { michael@0: section.Append("sugar "); michael@0: Label l; michael@0: { michael@0: Section middle; michael@0: Label m; michael@0: middle.B32(m); michael@0: section.Append(middle); michael@0: m = 0x66726565; michael@0: } michael@0: section.Append(" jazz"); michael@0: EXPECT_EQ(15U, section.Size()); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_STREQ(contents.c_str(), "sugar free jazz"); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0) { michael@0: section.LEB128(0); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\0", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x3f) { michael@0: section.LEB128(0x3f); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x3f", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x40) { michael@0: section.LEB128(0x40); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xc0\x00", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x7f) { michael@0: section.LEB128(0x7f); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x00", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x80) { michael@0: section.LEB128(0x80); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x01", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0xff) { michael@0: section.LEB128(0xff); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x01", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x1fff) { michael@0: section.LEB128(0x1fff); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x3f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_0x2000) { michael@0: section.LEB128(0x2000); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\xc0\x00", 3), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n1) { michael@0: section.LEB128(-1); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x7f", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x40) { michael@0: section.LEB128(-0x40); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x40", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x41) { michael@0: section.LEB128(-0x41); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xbf\x7f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x7f) { michael@0: section.LEB128(-0x7f); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x81\x7f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x80) { michael@0: section.LEB128(-0x80); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x7f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x2000) { michael@0: section.LEB128(-0x2000); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x40", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEB128_n0x2001) { michael@0: section.LEB128(-0x2001); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\xbf\x7f", 3), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0) { michael@0: section.ULEB128(0); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\0", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_1) { michael@0: section.ULEB128(1); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x01", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x3f) { michael@0: section.ULEB128(0x3f); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x3f", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x40) { michael@0: section.ULEB128(0x40); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x40", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x7f) { michael@0: section.ULEB128(0x7f); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x7f", 1), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x80) { michael@0: section.ULEB128(0x80); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x01", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0xff) { michael@0: section.ULEB128(0xff); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x01", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x100) { michael@0: section.ULEB128(0x100); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x02", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x1fff) { michael@0: section.ULEB128(0x1fff); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x3f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x2000) { michael@0: section.ULEB128(0x2000); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x40", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x3fff) { michael@0: section.ULEB128(0x3fff); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xff\x7f", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_0x4000) { michael@0: section.ULEB128(0x4000); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x80\x01", 3), contents); michael@0: } michael@0: michael@0: TEST_F(Append,ULEB128_12857) { michael@0: section.ULEB128(12857); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\xb9\x64", 2), contents); michael@0: } michael@0: michael@0: TEST_F(Append, LEBChain) { michael@0: section.LEB128(-0x80).ULEB128(12857).Append("*"); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(string("\x80\x7f\xb9\x64*", 5), contents); michael@0: } michael@0: michael@0: michael@0: class GetContents: public SectionFixture, public Test { }; michael@0: michael@0: TEST_F(GetContents, Undefined) { michael@0: Label l; michael@0: section.Append(kLittleEndian, 8, l); michael@0: ASSERT_FALSE(section.GetContents(&contents)); michael@0: } michael@0: michael@0: TEST_F(GetContents, ClearsContents) { michael@0: section.Append((size_t) 10, '*'); michael@0: EXPECT_EQ(10U, section.Size()); michael@0: EXPECT_TRUE(section.GetContents(&contents)); michael@0: EXPECT_EQ(0U, section.Size()); michael@0: } michael@0: michael@0: TEST_F(GetContents, ClearsReferences) { michael@0: Label l; michael@0: section.Append(kBigEndian, 1, l); michael@0: l = 42; michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_BYTES(contents, I1(42)); michael@0: ASSERT_TRUE(section.GetContents(&contents)); // should not die michael@0: } michael@0: michael@0: class Miscellanea: public SectionFixture, public Test { }; michael@0: michael@0: TEST_F(Miscellanea, Clear) { michael@0: section.Append("howdy"); michael@0: Label l; michael@0: section.L32(l); michael@0: EXPECT_EQ(9U, section.Size()); michael@0: section.Clear(); michael@0: EXPECT_EQ(0U, section.Size()); michael@0: l = 0x8d231bf0U; michael@0: ASSERT_TRUE(section.GetContents(&contents)); // should not die michael@0: } michael@0: michael@0: TEST_F(Miscellanea, Align) { michael@0: section.Append("*"); michael@0: EXPECT_EQ(1U, section.Size()); michael@0: section.Align(4).Append("*"); michael@0: EXPECT_EQ(5U, section.Size()); michael@0: section.Append("*").Align(2); michael@0: EXPECT_EQ(6U, section.Size()); michael@0: } michael@0: michael@0: TEST_F(Miscellanea, AlignPad) { michael@0: section.Append("*"); michael@0: EXPECT_EQ(1U, section.Size()); michael@0: section.Align(4, ' ').Append("*"); michael@0: EXPECT_EQ(5U, section.Size()); michael@0: section.Append("*").Align(2, ' '); michael@0: EXPECT_EQ(6U, section.Size()); michael@0: ASSERT_TRUE(section.GetContents(&contents)); michael@0: ASSERT_EQ(string("* **"), contents); michael@0: } michael@0: michael@0: TEST_F(Miscellanea, StartHereMark) { michael@0: Label m; michael@0: section.Append(42, ' ').Mark(&m).Append(13, '+'); michael@0: EXPECT_EQ(42U, m - section.start()); michael@0: EXPECT_EQ(42U + 13U, section.Here() - section.start()); michael@0: EXPECT_FALSE(section.start().IsKnownConstant()); michael@0: EXPECT_FALSE(m.IsKnownConstant()); michael@0: EXPECT_FALSE(section.Here().IsKnownConstant()); michael@0: } michael@0: michael@0: TEST_F(Miscellanea, Endianness) { michael@0: section.set_endianness(kBigEndian); michael@0: EXPECT_EQ(kBigEndian, section.endianness()); michael@0: section.set_endianness(kLittleEndian); michael@0: EXPECT_EQ(kLittleEndian, section.endianness()); michael@0: }