toolkit/crashreporter/google-breakpad/src/common/test_assembler_unittest.cc

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // Copyright (c) 2010, Google Inc.
michael@0 2 // All rights reserved.
michael@0 3 //
michael@0 4 // Redistribution and use in source and binary forms, with or without
michael@0 5 // modification, are permitted provided that the following conditions are
michael@0 6 // met:
michael@0 7 //
michael@0 8 // * Redistributions of source code must retain the above copyright
michael@0 9 // notice, this list of conditions and the following disclaimer.
michael@0 10 // * Redistributions in binary form must reproduce the above
michael@0 11 // copyright notice, this list of conditions and the following disclaimer
michael@0 12 // in the documentation and/or other materials provided with the
michael@0 13 // distribution.
michael@0 14 // * Neither the name of Google Inc. nor the names of its
michael@0 15 // contributors may be used to endorse or promote products derived from
michael@0 16 // this software without specific prior written permission.
michael@0 17 //
michael@0 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29
michael@0 30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
michael@0 31
michael@0 32 // test_assembler_unittest.cc: Unit tests for google_breakpad::TestAssembler.
michael@0 33
michael@0 34 #include <string>
michael@0 35 #include <string.h>
michael@0 36
michael@0 37 #include "breakpad_googletest_includes.h"
michael@0 38 #include "common/test_assembler.h"
michael@0 39 #include "common/using_std_string.h"
michael@0 40
michael@0 41 using google_breakpad::test_assembler::Label;
michael@0 42 using google_breakpad::test_assembler::Section;
michael@0 43 using google_breakpad::test_assembler::kBigEndian;
michael@0 44 using google_breakpad::test_assembler::kLittleEndian;
michael@0 45 using testing::Test;
michael@0 46
michael@0 47 TEST(ConstructLabel, Simple) {
michael@0 48 Label l;
michael@0 49 }
michael@0 50
michael@0 51 TEST(ConstructLabel, Undefined) {
michael@0 52 Label l;
michael@0 53 EXPECT_FALSE(l.IsKnownConstant());
michael@0 54 }
michael@0 55
michael@0 56 TEST(ConstructLabelDeathTest, Undefined) {
michael@0 57 Label l;
michael@0 58 ASSERT_DEATH(l.Value(), "IsKnownConstant\\(&v\\)");
michael@0 59 }
michael@0 60
michael@0 61 TEST(ConstructLabel, Constant) {
michael@0 62 Label l(0x060b9f974eaf301eULL);
michael@0 63 uint64_t v;
michael@0 64 EXPECT_TRUE(l.IsKnownConstant(&v));
michael@0 65 EXPECT_EQ(v, 0x060b9f974eaf301eULL);
michael@0 66 EXPECT_EQ(l.Value(), 0x060b9f974eaf301eULL);
michael@0 67 }
michael@0 68
michael@0 69 TEST(ConstructLabel, Copy) {
michael@0 70 Label l;
michael@0 71 Label m(l);
michael@0 72 uint64_t v;
michael@0 73 EXPECT_TRUE(l.IsKnownOffsetFrom(m, &v));
michael@0 74 EXPECT_EQ(0U, v);
michael@0 75 }
michael@0 76
michael@0 77 // The left-hand-side of a label assignment can be either
michael@0 78 // unconstrained, related, or known. The right-hand-side can be any of
michael@0 79 // those, or an integer.
michael@0 80 TEST(Assignment, UnconstrainedToUnconstrained) {
michael@0 81 Label l, m;
michael@0 82 l = m;
michael@0 83 EXPECT_EQ(0U, l-m);
michael@0 84 EXPECT_TRUE(l.IsKnownOffsetFrom(m));
michael@0 85 uint64_t d;
michael@0 86 EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
michael@0 87 EXPECT_EQ(0U, d);
michael@0 88 EXPECT_FALSE(l.IsKnownConstant());
michael@0 89 }
michael@0 90
michael@0 91 TEST(Assignment, UnconstrainedToRelated) {
michael@0 92 Label l, m, n;
michael@0 93 l = n;
michael@0 94 l = m;
michael@0 95 EXPECT_EQ(0U, l-m);
michael@0 96 EXPECT_TRUE(l.IsKnownOffsetFrom(m));
michael@0 97 uint64_t d;
michael@0 98 EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
michael@0 99 EXPECT_EQ(0U, d);
michael@0 100 EXPECT_FALSE(l.IsKnownConstant());
michael@0 101 }
michael@0 102
michael@0 103 TEST(Assignment, UnconstrainedToKnown) {
michael@0 104 Label l, m;
michael@0 105 l = 0x8fd16e55b20a39c1ULL;
michael@0 106 l = m;
michael@0 107 EXPECT_EQ(0U, l-m);
michael@0 108 EXPECT_TRUE(l.IsKnownOffsetFrom(m));
michael@0 109 uint64_t d;
michael@0 110 EXPECT_TRUE(l.IsKnownOffsetFrom(m, &d));
michael@0 111 EXPECT_EQ(0U, d);
michael@0 112 EXPECT_TRUE(m.IsKnownConstant());
michael@0 113 EXPECT_EQ(0x8fd16e55b20a39c1ULL, m.Value());
michael@0 114 }
michael@0 115
michael@0 116 TEST(Assignment, RelatedToUnconstrained) {
michael@0 117 Label l, m, n;
michael@0 118 m = n;
michael@0 119 l = m;
michael@0 120 EXPECT_EQ(0U, l-n);
michael@0 121 EXPECT_TRUE(l.IsKnownOffsetFrom(n));
michael@0 122 uint64_t d;
michael@0 123 EXPECT_TRUE(l.IsKnownOffsetFrom(n, &d));
michael@0 124 EXPECT_EQ(0U, d);
michael@0 125 EXPECT_FALSE(l.IsKnownConstant());
michael@0 126 }
michael@0 127
michael@0 128 TEST(Assignment, RelatedToRelated) {
michael@0 129 Label l, m, n, o;
michael@0 130 l = n;
michael@0 131 m = o;
michael@0 132 l = m;
michael@0 133 EXPECT_EQ(0U, n-o);
michael@0 134 EXPECT_TRUE(n.IsKnownOffsetFrom(o));
michael@0 135 uint64_t d;
michael@0 136 EXPECT_TRUE(n.IsKnownOffsetFrom(o, &d));
michael@0 137 EXPECT_EQ(0U, d);
michael@0 138 EXPECT_FALSE(l.IsKnownConstant());
michael@0 139 }
michael@0 140
michael@0 141 TEST(Assignment, RelatedToKnown) {
michael@0 142 Label l, m, n;
michael@0 143 m = n;
michael@0 144 l = 0xd2011f8c82ad56f2ULL;
michael@0 145 l = m;
michael@0 146 EXPECT_TRUE(l.IsKnownConstant());
michael@0 147 EXPECT_EQ(0xd2011f8c82ad56f2ULL, l.Value());
michael@0 148 EXPECT_TRUE(m.IsKnownConstant());
michael@0 149 EXPECT_EQ(0xd2011f8c82ad56f2ULL, m.Value());
michael@0 150 EXPECT_TRUE(n.IsKnownConstant());
michael@0 151 EXPECT_EQ(0xd2011f8c82ad56f2ULL, n.Value());
michael@0 152 }
michael@0 153
michael@0 154 TEST(Assignment, KnownToUnconstrained) {
michael@0 155 Label l, m;
michael@0 156 m = 0x50b024c0d6073887ULL;
michael@0 157 l = m;
michael@0 158 EXPECT_TRUE(l.IsKnownConstant());
michael@0 159 EXPECT_EQ(0x50b024c0d6073887ULL, l.Value());
michael@0 160 EXPECT_TRUE(m.IsKnownConstant());
michael@0 161 EXPECT_EQ(0x50b024c0d6073887ULL, m.Value());
michael@0 162 }
michael@0 163
michael@0 164 TEST(Assignment, KnownToRelated) {
michael@0 165 Label l, m, n;
michael@0 166 l = n;
michael@0 167 m = 0x5348883655c727e5ULL;
michael@0 168 l = m;
michael@0 169 EXPECT_TRUE(l.IsKnownConstant());
michael@0 170 EXPECT_EQ(0x5348883655c727e5ULL, l.Value());
michael@0 171 EXPECT_TRUE(m.IsKnownConstant());
michael@0 172 EXPECT_EQ(0x5348883655c727e5ULL, m.Value());
michael@0 173 EXPECT_TRUE(n.IsKnownConstant());
michael@0 174 EXPECT_EQ(0x5348883655c727e5ULL, n.Value());
michael@0 175 }
michael@0 176
michael@0 177 TEST(Assignment, KnownToKnown) {
michael@0 178 Label l, m;
michael@0 179 l = 0x36c209c20987564eULL;
michael@0 180 m = 0x36c209c20987564eULL;
michael@0 181 l = m;
michael@0 182 EXPECT_TRUE(l.IsKnownConstant());
michael@0 183 EXPECT_EQ(0x36c209c20987564eULL, l.Value());
michael@0 184 EXPECT_TRUE(m.IsKnownConstant());
michael@0 185 EXPECT_EQ(0x36c209c20987564eULL, m.Value());
michael@0 186 }
michael@0 187
michael@0 188 TEST(Assignment, ConstantToUnconstrained) {
michael@0 189 Label l;
michael@0 190 l = 0xc02495f4d7f5a957ULL;
michael@0 191 EXPECT_TRUE(l.IsKnownConstant());
michael@0 192 EXPECT_EQ(0xc02495f4d7f5a957ULL, l.Value());
michael@0 193 }
michael@0 194
michael@0 195 TEST(Assignment, ConstantToRelated) {
michael@0 196 Label l, m;
michael@0 197 l = m;
michael@0 198 l = 0x4577901cf275488dULL;
michael@0 199 EXPECT_TRUE(l.IsKnownConstant());
michael@0 200 EXPECT_EQ(0x4577901cf275488dULL, l.Value());
michael@0 201 EXPECT_TRUE(m.IsKnownConstant());
michael@0 202 EXPECT_EQ(0x4577901cf275488dULL, m.Value());
michael@0 203 }
michael@0 204
michael@0 205 TEST(Assignment, ConstantToKnown) {
michael@0 206 Label l;
michael@0 207 l = 0xec0b9c369b7e8ea7ULL;
michael@0 208 l = 0xec0b9c369b7e8ea7ULL;
michael@0 209 EXPECT_TRUE(l.IsKnownConstant());
michael@0 210 EXPECT_EQ(0xec0b9c369b7e8ea7ULL, l.Value());
michael@0 211 }
michael@0 212
michael@0 213 TEST(AssignmentDeathTest, Self) {
michael@0 214 Label l;
michael@0 215 ASSERT_DEATH(l = l, "binding != this");
michael@0 216 }
michael@0 217
michael@0 218 TEST(AssignmentDeathTest, IndirectCycle) {
michael@0 219 Label l, m, n;
michael@0 220 l = m;
michael@0 221 m = n;
michael@0 222 ASSERT_DEATH(n = l, "binding != this");
michael@0 223 }
michael@0 224
michael@0 225 TEST(AssignmentDeathTest, Cycle) {
michael@0 226 Label l, m, n, o;
michael@0 227 l = m;
michael@0 228 m = n;
michael@0 229 o = n;
michael@0 230 ASSERT_DEATH(o = l, "binding != this");
michael@0 231 }
michael@0 232
michael@0 233 TEST(Addition, LabelConstant) {
michael@0 234 Label l, m;
michael@0 235 m = l + 0x5248d93e8bbe9497ULL;
michael@0 236 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 237 uint64_t d;
michael@0 238 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 239 EXPECT_EQ(0x5248d93e8bbe9497ULL, d);
michael@0 240 EXPECT_FALSE(m.IsKnownConstant());
michael@0 241 }
michael@0 242
michael@0 243 TEST(Addition, ConstantLabel) {
michael@0 244 Label l, m;
michael@0 245 m = 0xf51e94e00d6e3c84ULL + l;
michael@0 246 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 247 uint64_t d;
michael@0 248 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 249 EXPECT_EQ(0xf51e94e00d6e3c84ULL, d);
michael@0 250 EXPECT_FALSE(m.IsKnownConstant());
michael@0 251 }
michael@0 252
michael@0 253 TEST(Addition, KnownLabelConstant) {
michael@0 254 Label l, m;
michael@0 255 l = 0x16286307042ce0d8ULL;
michael@0 256 m = l + 0x3fdddd91306719d7ULL;
michael@0 257 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 258 uint64_t d;
michael@0 259 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 260 EXPECT_EQ(0x3fdddd91306719d7ULL, d);
michael@0 261 EXPECT_TRUE(m.IsKnownConstant());
michael@0 262 EXPECT_EQ(0x16286307042ce0d8ULL + 0x3fdddd91306719d7ULL, m.Value());
michael@0 263 }
michael@0 264
michael@0 265 TEST(Addition, ConstantKnownLabel) {
michael@0 266 Label l, m;
michael@0 267 l = 0x50f62d0cdd1031deULL;
michael@0 268 m = 0x1b13462d8577c538ULL + l;
michael@0 269 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 270 uint64_t d;
michael@0 271 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 272 EXPECT_EQ(0x1b13462d8577c538ULL, d);
michael@0 273 EXPECT_TRUE(m.IsKnownConstant());
michael@0 274 EXPECT_EQ(0x50f62d0cdd1031deULL + 0x1b13462d8577c538ULL, m.Value());
michael@0 275 }
michael@0 276
michael@0 277 TEST(Subtraction, LabelConstant) {
michael@0 278 Label l, m;
michael@0 279 m = l - 0x0620884d21d3138eULL;
michael@0 280 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 281 uint64_t d;
michael@0 282 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 283 EXPECT_EQ(-0x0620884d21d3138eULL, d);
michael@0 284 EXPECT_FALSE(m.IsKnownConstant());
michael@0 285 }
michael@0 286
michael@0 287 TEST(Subtraction, KnownLabelConstant) {
michael@0 288 Label l, m;
michael@0 289 l = 0x6237fbaf9ef7929eULL;
michael@0 290 m = l - 0x317730995d2ab6eeULL;
michael@0 291 EXPECT_TRUE(m.IsKnownOffsetFrom(l));
michael@0 292 uint64_t d;
michael@0 293 EXPECT_TRUE(m.IsKnownOffsetFrom(l, &d));
michael@0 294 EXPECT_EQ(-0x317730995d2ab6eeULL, d);
michael@0 295 EXPECT_TRUE(m.IsKnownConstant());
michael@0 296 EXPECT_EQ(0x6237fbaf9ef7929eULL - 0x317730995d2ab6eeULL, m.Value());
michael@0 297 }
michael@0 298
michael@0 299 TEST(SubtractionDeathTest, LabelLabel) {
michael@0 300 Label l, m;
michael@0 301 ASSERT_DEATH(l - m, "IsKnownOffsetFrom\\(label, &offset\\)");
michael@0 302 }
michael@0 303
michael@0 304 TEST(Subtraction, LabelLabel) {
michael@0 305 Label l, m;
michael@0 306 l = m + 0x7fa77ec63e28a17aULL;
michael@0 307 EXPECT_EQ(0x7fa77ec63e28a17aULL, l - m);
michael@0 308 EXPECT_EQ(-0x7fa77ec63e28a17aULL, m - l);
michael@0 309 }
michael@0 310
michael@0 311 TEST(IsKnownConstant, Undefined) {
michael@0 312 Label l;
michael@0 313 EXPECT_FALSE(l.IsKnownConstant());
michael@0 314 }
michael@0 315
michael@0 316 TEST(IsKnownConstant, RelatedLabel) {
michael@0 317 Label l, m;
michael@0 318 l = m;
michael@0 319 EXPECT_FALSE(l.IsKnownConstant());
michael@0 320 EXPECT_FALSE(m.IsKnownConstant());
michael@0 321 }
michael@0 322
michael@0 323 TEST(IsKnownConstant, Constant) {
michael@0 324 Label l;
michael@0 325 l = 0xf374b1bdd6a22576ULL;
michael@0 326 EXPECT_TRUE(l.IsKnownConstant());
michael@0 327 }
michael@0 328
michael@0 329 TEST(IsKnownOffsetFrom, Unrelated) {
michael@0 330 Label l, m;
michael@0 331 EXPECT_FALSE(l.IsKnownOffsetFrom(m));
michael@0 332 }
michael@0 333
michael@0 334 TEST(IsKnownOffsetFrom, Related) {
michael@0 335 Label l, m;
michael@0 336 l = m;
michael@0 337 EXPECT_TRUE(l.IsKnownOffsetFrom(m));
michael@0 338 }
michael@0 339
michael@0 340 // Test the construction of chains of related labels, and the
michael@0 341 // propagation of values through them.
michael@0 342 //
michael@0 343 // Although the relations between labels are supposed to behave
michael@0 344 // symmetrically --- that is, 'a = b' should put a and b in
michael@0 345 // indistinguishable states --- there's a distinction made internally
michael@0 346 // between the target (a) and the source (b).
michael@0 347 //
michael@0 348 // So there are five test axes to cover:
michael@0 349 //
michael@0 350 // - Do we construct the chain with assignment ("Assign") or with constructors
michael@0 351 // ("Construct")?
michael@0 352 //
michael@0 353 // - Do we set the value of the label at the start of the chain
michael@0 354 // ("Start") or the label at the end ("End")?
michael@0 355 //
michael@0 356 // - Are we testing the propagation of a relationship between variable
michael@0 357 // values ("Relation"), or the propagation of a known constant value
michael@0 358 // ("Value")?
michael@0 359 //
michael@0 360 // - Do we set the value before building the chain ("Before") or after
michael@0 361 // the chain has been built ("After")?
michael@0 362 //
michael@0 363 // - Do we add new relationships to the end of the existing chain
michael@0 364 // ("Forward") or to the beginning ("Backward")?
michael@0 365 //
michael@0 366 // Of course, "Construct" and "Backward" can't be combined, which
michael@0 367 // eliminates eight combinations, and "Construct", "End", and "Before"
michael@0 368 // can't be combined, which eliminates two more, so there are are 22
michael@0 369 // combinations, not 32.
michael@0 370
michael@0 371 TEST(LabelChain, AssignStartRelationBeforeForward) {
michael@0 372 Label a, b, c, d;
michael@0 373 Label x;
michael@0 374 a = x;
michael@0 375 b = a + 0x1;
michael@0 376 c = b + 0x10;
michael@0 377 d = c + 0x100;
michael@0 378 EXPECT_EQ(0x111U, d-x);
michael@0 379 EXPECT_EQ(0x11U, c-x);
michael@0 380 EXPECT_EQ(0x1U, b-x);
michael@0 381 EXPECT_EQ(0U, a-x);
michael@0 382 }
michael@0 383
michael@0 384 TEST(LabelChain, AssignStartRelationBeforeBackward) {
michael@0 385 Label a, b, c, d;
michael@0 386 Label x;
michael@0 387 a = x;
michael@0 388 d = c + 0x100;
michael@0 389 c = b + 0x10;
michael@0 390 b = a + 0x1;
michael@0 391 EXPECT_EQ(0x111U, d-x);
michael@0 392 EXPECT_EQ(0x11U, c-x);
michael@0 393 EXPECT_EQ(0x1U, b-x);
michael@0 394 EXPECT_EQ(0U, a-x);
michael@0 395 }
michael@0 396
michael@0 397 TEST(LabelChain, AssignStartRelationAfterForward) {
michael@0 398 Label a, b, c, d;
michael@0 399 Label x;
michael@0 400 b = a + 0x1;
michael@0 401 c = b + 0x10;
michael@0 402 d = c + 0x100;
michael@0 403 a = x;
michael@0 404 EXPECT_EQ(0x111U, d-x);
michael@0 405 EXPECT_EQ(0x11U, c-x);
michael@0 406 EXPECT_EQ(0x1U, b-x);
michael@0 407 EXPECT_EQ(0U, a-x);
michael@0 408 }
michael@0 409
michael@0 410 TEST(LabelChain, AssignStartRelationAfterBackward) {
michael@0 411 Label a, b, c, d;
michael@0 412 Label x;
michael@0 413 d = c + 0x100;
michael@0 414 c = b + 0x10;
michael@0 415 b = a + 0x1;
michael@0 416 a = x;
michael@0 417 EXPECT_EQ(0x111U, d-x);
michael@0 418 EXPECT_EQ(0x11U, c-x);
michael@0 419 EXPECT_EQ(0x1U, b-x);
michael@0 420 EXPECT_EQ(0U, a-x);
michael@0 421 }
michael@0 422
michael@0 423 TEST(LabelChain, AssignStartValueBeforeForward) {
michael@0 424 Label a, b, c, d;
michael@0 425 a = 0xa131200190546ac2ULL;
michael@0 426 b = a + 0x1;
michael@0 427 c = b + 0x10;
michael@0 428 d = c + 0x100;
michael@0 429 EXPECT_EQ(0xa131200190546ac2ULL + 0x111U, d.Value());
michael@0 430 EXPECT_EQ(0xa131200190546ac2ULL + 0x11U, c.Value());
michael@0 431 EXPECT_EQ(0xa131200190546ac2ULL + 0x1U, b.Value());
michael@0 432 EXPECT_EQ(0xa131200190546ac2ULL + 0U, a.Value());
michael@0 433 }
michael@0 434
michael@0 435 TEST(LabelChain, AssignStartValueBeforeBackward) {
michael@0 436 Label a, b, c, d;
michael@0 437 a = 0x8da17e1670ad4fa2ULL;
michael@0 438 d = c + 0x100;
michael@0 439 c = b + 0x10;
michael@0 440 b = a + 0x1;
michael@0 441 EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x111U, d.Value());
michael@0 442 EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x11U, c.Value());
michael@0 443 EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0x1U, b.Value());
michael@0 444 EXPECT_EQ(0x8da17e1670ad4fa2ULL + 0U, a.Value());
michael@0 445 }
michael@0 446
michael@0 447 TEST(LabelChain, AssignStartValueAfterForward) {
michael@0 448 Label a, b, c, d;
michael@0 449 b = a + 0x1;
michael@0 450 c = b + 0x10;
michael@0 451 d = c + 0x100;
michael@0 452 a = 0x99b8f51bafd41adaULL;
michael@0 453 EXPECT_EQ(0x99b8f51bafd41adaULL + 0x111U, d.Value());
michael@0 454 EXPECT_EQ(0x99b8f51bafd41adaULL + 0x11U, c.Value());
michael@0 455 EXPECT_EQ(0x99b8f51bafd41adaULL + 0x1U, b.Value());
michael@0 456 EXPECT_EQ(0x99b8f51bafd41adaULL + 0U, a.Value());
michael@0 457 }
michael@0 458
michael@0 459 TEST(LabelChain, AssignStartValueAfterBackward) {
michael@0 460 Label a, b, c, d;
michael@0 461 d = c + 0x100;
michael@0 462 c = b + 0x10;
michael@0 463 b = a + 0x1;
michael@0 464 a = 0xc86ca1d97ab5df6eULL;
michael@0 465 EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x111U, d.Value());
michael@0 466 EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x11U, c.Value());
michael@0 467 EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0x1U, b.Value());
michael@0 468 EXPECT_EQ(0xc86ca1d97ab5df6eULL + 0U, a.Value());
michael@0 469 }
michael@0 470
michael@0 471 TEST(LabelChain, AssignEndRelationBeforeForward) {
michael@0 472 Label a, b, c, d;
michael@0 473 Label x;
michael@0 474 x = d;
michael@0 475 b = a + 0x1;
michael@0 476 c = b + 0x10;
michael@0 477 d = c + 0x100;
michael@0 478 EXPECT_EQ(-(uint64_t)0x111U, a-x);
michael@0 479 EXPECT_EQ(-(uint64_t)0x110U, b-x);
michael@0 480 EXPECT_EQ(-(uint64_t)0x100U, c-x);
michael@0 481 EXPECT_EQ(-(uint64_t)0U, d-x);
michael@0 482 }
michael@0 483
michael@0 484 TEST(LabelChain, AssignEndRelationBeforeBackward) {
michael@0 485 Label a, b, c, d;
michael@0 486 Label x;
michael@0 487 x = d;
michael@0 488 d = c + 0x100;
michael@0 489 c = b + 0x10;
michael@0 490 b = a + 0x1;
michael@0 491 EXPECT_EQ(-(uint64_t)0x111U, a-x);
michael@0 492 EXPECT_EQ(-(uint64_t)0x110U, b-x);
michael@0 493 EXPECT_EQ(-(uint64_t)0x100U, c-x);
michael@0 494 EXPECT_EQ(-(uint64_t)0U, d-x);
michael@0 495 }
michael@0 496
michael@0 497 TEST(LabelChain, AssignEndRelationAfterForward) {
michael@0 498 Label a, b, c, d;
michael@0 499 Label x;
michael@0 500 b = a + 0x1;
michael@0 501 c = b + 0x10;
michael@0 502 d = c + 0x100;
michael@0 503 x = d;
michael@0 504 EXPECT_EQ(-(uint64_t)0x111U, a-x);
michael@0 505 EXPECT_EQ(-(uint64_t)0x110U, b-x);
michael@0 506 EXPECT_EQ(-(uint64_t)0x100U, c-x);
michael@0 507 EXPECT_EQ(-(uint64_t)0x000U, d-x);
michael@0 508 }
michael@0 509
michael@0 510 TEST(LabelChain, AssignEndRelationAfterBackward) {
michael@0 511 Label a, b, c, d;
michael@0 512 Label x;
michael@0 513 d = c + 0x100;
michael@0 514 c = b + 0x10;
michael@0 515 b = a + 0x1;
michael@0 516 x = d;
michael@0 517 EXPECT_EQ(-(uint64_t)0x111U, a-x);
michael@0 518 EXPECT_EQ(-(uint64_t)0x110U, b-x);
michael@0 519 EXPECT_EQ(-(uint64_t)0x100U, c-x);
michael@0 520 EXPECT_EQ(-(uint64_t)0x000U, d-x);
michael@0 521 }
michael@0 522
michael@0 523 TEST(LabelChain, AssignEndValueBeforeForward) {
michael@0 524 Label a, b, c, d;
michael@0 525 d = 0xa131200190546ac2ULL;
michael@0 526 b = a + 0x1;
michael@0 527 c = b + 0x10;
michael@0 528 d = c + 0x100;
michael@0 529 EXPECT_EQ(0xa131200190546ac2ULL - 0x111, a.Value());
michael@0 530 EXPECT_EQ(0xa131200190546ac2ULL - 0x110, b.Value());
michael@0 531 EXPECT_EQ(0xa131200190546ac2ULL - 0x100, c.Value());
michael@0 532 EXPECT_EQ(0xa131200190546ac2ULL - 0x000, d.Value());
michael@0 533 }
michael@0 534
michael@0 535 TEST(LabelChain, AssignEndValueBeforeBackward) {
michael@0 536 Label a, b, c, d;
michael@0 537 d = 0x8da17e1670ad4fa2ULL;
michael@0 538 d = c + 0x100;
michael@0 539 c = b + 0x10;
michael@0 540 b = a + 0x1;
michael@0 541 EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x111, a.Value());
michael@0 542 EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x110, b.Value());
michael@0 543 EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x100, c.Value());
michael@0 544 EXPECT_EQ(0x8da17e1670ad4fa2ULL - 0x000, d.Value());
michael@0 545 }
michael@0 546
michael@0 547 TEST(LabelChain, AssignEndValueAfterForward) {
michael@0 548 Label a, b, c, d;
michael@0 549 b = a + 0x1;
michael@0 550 c = b + 0x10;
michael@0 551 d = c + 0x100;
michael@0 552 d = 0x99b8f51bafd41adaULL;
michael@0 553 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x111, a.Value());
michael@0 554 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x110, b.Value());
michael@0 555 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x100, c.Value());
michael@0 556 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x000, d.Value());
michael@0 557 }
michael@0 558
michael@0 559 TEST(LabelChain, AssignEndValueAfterBackward) {
michael@0 560 Label a, b, c, d;
michael@0 561 d = c + 0x100;
michael@0 562 c = b + 0x10;
michael@0 563 b = a + 0x1;
michael@0 564 d = 0xc86ca1d97ab5df6eULL;
michael@0 565 EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x111, a.Value());
michael@0 566 EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x110, b.Value());
michael@0 567 EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x100, c.Value());
michael@0 568 EXPECT_EQ(0xc86ca1d97ab5df6eULL - 0x000, d.Value());
michael@0 569 }
michael@0 570
michael@0 571 TEST(LabelChain, ConstructStartRelationBeforeForward) {
michael@0 572 Label x;
michael@0 573 Label a(x);
michael@0 574 Label b(a + 0x1);
michael@0 575 Label c(b + 0x10);
michael@0 576 Label d(c + 0x100);
michael@0 577 EXPECT_EQ(0x111U, d-x);
michael@0 578 EXPECT_EQ(0x11U, c-x);
michael@0 579 EXPECT_EQ(0x1U, b-x);
michael@0 580 EXPECT_EQ(0U, a-x);
michael@0 581 }
michael@0 582
michael@0 583 TEST(LabelChain, ConstructStartRelationAfterForward) {
michael@0 584 Label x;
michael@0 585 Label a;
michael@0 586 Label b(a + 0x1);
michael@0 587 Label c(b + 0x10);
michael@0 588 Label d(c + 0x100);
michael@0 589 a = x;
michael@0 590 EXPECT_EQ(0x111U, d-x);
michael@0 591 EXPECT_EQ(0x11U, c-x);
michael@0 592 EXPECT_EQ(0x1U, b-x);
michael@0 593 EXPECT_EQ(0U, a-x);
michael@0 594 }
michael@0 595
michael@0 596 TEST(LabelChain, ConstructStartValueBeforeForward) {
michael@0 597 Label a(0x5d234d177d01ccc8ULL);
michael@0 598 Label b(a + 0x1);
michael@0 599 Label c(b + 0x10);
michael@0 600 Label d(c + 0x100);
michael@0 601 EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x111U, d.Value());
michael@0 602 EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x011U, c.Value());
michael@0 603 EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x001U, b.Value());
michael@0 604 EXPECT_EQ(0x5d234d177d01ccc8ULL + 0x000U, a.Value());
michael@0 605 }
michael@0 606
michael@0 607 TEST(LabelChain, ConstructStartValueAfterForward) {
michael@0 608 Label a;
michael@0 609 Label b(a + 0x1);
michael@0 610 Label c(b + 0x10);
michael@0 611 Label d(c + 0x100);
michael@0 612 a = 0xded85d54586e84fcULL;
michael@0 613 EXPECT_EQ(0xded85d54586e84fcULL + 0x111U, d.Value());
michael@0 614 EXPECT_EQ(0xded85d54586e84fcULL + 0x011U, c.Value());
michael@0 615 EXPECT_EQ(0xded85d54586e84fcULL + 0x001U, b.Value());
michael@0 616 EXPECT_EQ(0xded85d54586e84fcULL + 0x000U, a.Value());
michael@0 617 }
michael@0 618
michael@0 619 TEST(LabelChain, ConstructEndRelationAfterForward) {
michael@0 620 Label x;
michael@0 621 Label a;
michael@0 622 Label b(a + 0x1);
michael@0 623 Label c(b + 0x10);
michael@0 624 Label d(c + 0x100);
michael@0 625 x = d;
michael@0 626 EXPECT_EQ(-(uint64_t)0x111U, a-x);
michael@0 627 EXPECT_EQ(-(uint64_t)0x110U, b-x);
michael@0 628 EXPECT_EQ(-(uint64_t)0x100U, c-x);
michael@0 629 EXPECT_EQ(-(uint64_t)0x000U, d-x);
michael@0 630 }
michael@0 631
michael@0 632 TEST(LabelChain, ConstructEndValueAfterForward) {
michael@0 633 Label a;
michael@0 634 Label b(a + 0x1);
michael@0 635 Label c(b + 0x10);
michael@0 636 Label d(c + 0x100);
michael@0 637 d = 0x99b8f51bafd41adaULL;
michael@0 638 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x111, a.Value());
michael@0 639 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x110, b.Value());
michael@0 640 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x100, c.Value());
michael@0 641 EXPECT_EQ(0x99b8f51bafd41adaULL - 0x000, d.Value());
michael@0 642 }
michael@0 643
michael@0 644 TEST(LabelTree, KnownValue) {
michael@0 645 Label l, m, n, o, p;
michael@0 646 l = m;
michael@0 647 m = n;
michael@0 648 o = p;
michael@0 649 p = n;
michael@0 650 l = 0x536b5de3d468a1b5ULL;
michael@0 651 EXPECT_EQ(0x536b5de3d468a1b5ULL, o.Value());
michael@0 652 }
michael@0 653
michael@0 654 TEST(LabelTree, Related) {
michael@0 655 Label l, m, n, o, p;
michael@0 656 l = m - 1;
michael@0 657 m = n - 10;
michael@0 658 o = p + 100;
michael@0 659 p = n + 1000;
michael@0 660 EXPECT_EQ(1111U, o - l);
michael@0 661 }
michael@0 662
michael@0 663 TEST(EquationDeathTest, EqualConstants) {
michael@0 664 Label m = 0x0d3962f280f07d24ULL;
michael@0 665 Label n = 0x0d3962f280f07d24ULL;
michael@0 666 m = n; // no death expected
michael@0 667 }
michael@0 668
michael@0 669 TEST(EquationDeathTest, EqualIndirectConstants) {
michael@0 670 Label m = 0xa347f1e5238fe6a1ULL;
michael@0 671 Label n;
michael@0 672 Label o = n;
michael@0 673 n = 0xa347f1e5238fe6a1ULL;
michael@0 674 n = m; // no death expected
michael@0 675 }
michael@0 676
michael@0 677 TEST(EquationDeathTest, ConstantClash) {
michael@0 678 Label m = 0xd4cc0f4f630ec741ULL;
michael@0 679 Label n = 0x934cd2d8254fc3eaULL;
michael@0 680 ASSERT_DEATH(m = n, "addend_ == addend");
michael@0 681 }
michael@0 682
michael@0 683 TEST(EquationDeathTest, IndirectConstantClash) {
michael@0 684 Label m = 0xd4cc0f4f630ec741ULL;
michael@0 685 Label n, o;
michael@0 686 n = o;
michael@0 687 o = 0xcfbe3b83ac49ce86ULL;
michael@0 688 ASSERT_DEATH(m = n, "addend_ == addend");
michael@0 689 }
michael@0 690
michael@0 691 // Assigning to a related label may free the next Binding on its
michael@0 692 // chain. This test always passes; it is interesting to memory
michael@0 693 // checkers and coverage analysis.
michael@0 694 TEST(LabelReferenceCount, AssignmentFree) {
michael@0 695 Label l;
michael@0 696 {
michael@0 697 Label m;
michael@0 698 l = m;
michael@0 699 }
michael@0 700 // This should free m's Binding.
michael@0 701 l = 0xca8bae92f0376d4fULL;
michael@0 702 ASSERT_EQ(0xca8bae92f0376d4fULL, l.Value());
michael@0 703 }
michael@0 704
michael@0 705 // Finding the value of a label may free the Binding it refers to. This test
michael@0 706 // always passes; it is interesting to memory checkers and coverage analysis.
michael@0 707 TEST(LabelReferenceCount, FindValueFree) {
michael@0 708 Label l;
michael@0 709 {
michael@0 710 Label m, n;
michael@0 711 l = m;
michael@0 712 m = n;
michael@0 713 n = 0x7a0b0c576672daafULL;
michael@0 714 // At this point, l's Binding refers to m's Binding, which refers
michael@0 715 // to n's binding.
michael@0 716 }
michael@0 717 // Now, l is the only reference keeping the three Bindings alive.
michael@0 718 // Resolving its value should free l's and m's original bindings.
michael@0 719 ASSERT_EQ(0x7a0b0c576672daafULL, l.Value());
michael@0 720 }
michael@0 721
michael@0 722 TEST(ConstructSection, Simple) {
michael@0 723 Section s;
michael@0 724 }
michael@0 725
michael@0 726 TEST(ConstructSection, WithEndian) {
michael@0 727 Section s(kBigEndian);
michael@0 728 }
michael@0 729
michael@0 730 // A fixture class for TestAssembler::Section tests.
michael@0 731 class SectionFixture {
michael@0 732 public:
michael@0 733 Section section;
michael@0 734 string contents;
michael@0 735 static const uint8_t data[];
michael@0 736 static const size_t data_size;
michael@0 737 };
michael@0 738
michael@0 739 const uint8_t SectionFixture::data[] = {
michael@0 740 0x87, 0x4f, 0x43, 0x67, 0x30, 0xd0, 0xd4, 0x0e
michael@0 741 };
michael@0 742
michael@0 743 #define I0()
michael@0 744 #define I1(a) { a }
michael@0 745 #define I2(a,b) { a,b }
michael@0 746 #define I3(a,b,c) { a,b,c }
michael@0 747 #define I4(a,b,c,d) { a,b,c,d }
michael@0 748 #define I5(a,b,c,d,e) { a,b,c,d,e }
michael@0 749 #define I6(a,b,c,d,e,f) { a,b,c,d,e,f }
michael@0 750 #define I7(a,b,c,d,e,f,g) { a,b,c,d,e,f,g }
michael@0 751 #define I8(a,b,c,d,e,f,g,h) { a,b,c,d,e,f,g,h }
michael@0 752 #define I9(a,b,c,d,e,f,g,h,i) { a,b,c,d,e,f,g,h,i }
michael@0 753 #define ASSERT_BYTES(s, b) \
michael@0 754 do \
michael@0 755 { \
michael@0 756 static const uint8_t expected_bytes[] = b; \
michael@0 757 ASSERT_EQ(sizeof(expected_bytes), s.size()); \
michael@0 758 ASSERT_TRUE(memcmp(s.data(), (const char *) expected_bytes, \
michael@0 759 sizeof(expected_bytes)) == 0); \
michael@0 760 } \
michael@0 761 while(0)
michael@0 762
michael@0 763 class Append: public SectionFixture, public Test { };
michael@0 764
michael@0 765 TEST_F(Append, Bytes) {
michael@0 766 section.Append(data, sizeof(data));
michael@0 767 ASSERT_TRUE(section.GetContents(&contents));
michael@0 768 ASSERT_EQ(sizeof(data), contents.size());
michael@0 769 EXPECT_TRUE(0 == memcmp(contents.data(), (const char *) data, sizeof(data)));
michael@0 770 }
michael@0 771
michael@0 772 TEST_F(Append, BytesTwice) {
michael@0 773 section.Append(data, sizeof(data));
michael@0 774 section.Append(data, sizeof(data));
michael@0 775 ASSERT_TRUE(section.GetContents(&contents));
michael@0 776 ASSERT_EQ(2 * sizeof(data), contents.size());
michael@0 777 ASSERT_TRUE(0 == memcmp(contents.data(), (const char *) data, sizeof(data)));
michael@0 778 ASSERT_TRUE(0 == memcmp(contents.data() + sizeof(data),
michael@0 779 (const char *) data, sizeof(data)));
michael@0 780 }
michael@0 781
michael@0 782 TEST_F(Append, String) {
michael@0 783 string s1 = "howdy ";
michael@0 784 string s2 = "there";
michael@0 785 section.Append(s1);
michael@0 786 section.Append(s2);
michael@0 787 ASSERT_TRUE(section.GetContents(&contents));
michael@0 788 ASSERT_STREQ(contents.c_str(), "howdy there");
michael@0 789 }
michael@0 790
michael@0 791 TEST_F(Append, CString) {
michael@0 792 section.AppendCString("howdy");
michael@0 793 section.AppendCString("");
michael@0 794 section.AppendCString("there");
michael@0 795 ASSERT_TRUE(section.GetContents(&contents));
michael@0 796 ASSERT_EQ(string("howdy\0\0there\0", 13), contents);
michael@0 797 }
michael@0 798
michael@0 799 TEST_F(Append, CStringSize) {
michael@0 800 section.AppendCString("howdy", 3);
michael@0 801 section.AppendCString("there", 5);
michael@0 802 section.AppendCString("fred", 6);
michael@0 803 section.AppendCString("natalie", 0);
michael@0 804 section.AppendCString("", 10);
michael@0 805 ASSERT_TRUE(section.GetContents(&contents));
michael@0 806 ASSERT_EQ(string("howtherefred\0\0\0\0\0\0\0\0\0\0\0\0", 24), contents);
michael@0 807 }
michael@0 808
michael@0 809 TEST_F(Append, RepeatedBytes) {
michael@0 810 section.Append((size_t) 10, '*');
michael@0 811 ASSERT_TRUE(section.GetContents(&contents));
michael@0 812 ASSERT_STREQ(contents.c_str(), "**********");
michael@0 813 }
michael@0 814
michael@0 815 TEST_F(Append, GeneralLE1) {
michael@0 816 section.Append(kLittleEndian, 1, 42);
michael@0 817 ASSERT_TRUE(section.GetContents(&contents));
michael@0 818 ASSERT_BYTES(contents, I1(42));
michael@0 819 }
michael@0 820
michael@0 821 TEST_F(Append, GeneralLE2) {
michael@0 822 section.Append(kLittleEndian, 2, 0x15a1);
michael@0 823 ASSERT_TRUE(section.GetContents(&contents));
michael@0 824 ASSERT_BYTES(contents, I2(0xa1, 0x15));
michael@0 825 }
michael@0 826
michael@0 827 TEST_F(Append, GeneralLE3) {
michael@0 828 section.Append(kLittleEndian, 3, 0x59ae8d);
michael@0 829 ASSERT_TRUE(section.GetContents(&contents));
michael@0 830 ASSERT_BYTES(contents, I3(0x8d, 0xae, 0x59));
michael@0 831 }
michael@0 832
michael@0 833 TEST_F(Append, GeneralLE4) {
michael@0 834 section.Append(kLittleEndian, 4, 0x51603c56);
michael@0 835 ASSERT_TRUE(section.GetContents(&contents));
michael@0 836 ASSERT_BYTES(contents, I4(0x56, 0x3c, 0x60, 0x51));
michael@0 837 }
michael@0 838
michael@0 839 TEST_F(Append, GeneralLE5) {
michael@0 840 section.Append(kLittleEndian, 5, 0x385e2803b4ULL);
michael@0 841 ASSERT_TRUE(section.GetContents(&contents));
michael@0 842 ASSERT_BYTES(contents, I5(0xb4, 0x03, 0x28, 0x5e, 0x38));
michael@0 843 }
michael@0 844
michael@0 845 TEST_F(Append, GeneralLE6) {
michael@0 846 section.Append(kLittleEndian, 6, 0xc7db9534dd1fULL);
michael@0 847 ASSERT_TRUE(section.GetContents(&contents));
michael@0 848 ASSERT_BYTES(contents, I6(0x1f, 0xdd, 0x34, 0x95, 0xdb, 0xc7));
michael@0 849 }
michael@0 850
michael@0 851 TEST_F(Append, GeneralLE7) {
michael@0 852 section.Append(kLittleEndian, 7, 0x1445c9f1b843e6ULL);
michael@0 853 ASSERT_TRUE(section.GetContents(&contents));
michael@0 854 ASSERT_BYTES(contents, I7(0xe6, 0x43, 0xb8, 0xf1, 0xc9, 0x45, 0x14));
michael@0 855 }
michael@0 856
michael@0 857 TEST_F(Append, GeneralLE8) {
michael@0 858 section.Append(kLittleEndian, 8, 0xaf48019dfe5c01e5ULL);
michael@0 859 ASSERT_TRUE(section.GetContents(&contents));
michael@0 860 ASSERT_BYTES(contents, I8(0xe5, 0x01, 0x5c, 0xfe, 0x9d, 0x01, 0x48, 0xaf));
michael@0 861 }
michael@0 862
michael@0 863 TEST_F(Append, GeneralBE1) {
michael@0 864 section.Append(kBigEndian, 1, 0xd0ULL);
michael@0 865 ASSERT_TRUE(section.GetContents(&contents));
michael@0 866 ASSERT_BYTES(contents, I1(0xd0));
michael@0 867 }
michael@0 868
michael@0 869 TEST_F(Append, GeneralBE2) {
michael@0 870 section.Append(kBigEndian, 2, 0x2e7eULL);
michael@0 871 ASSERT_TRUE(section.GetContents(&contents));
michael@0 872 ASSERT_BYTES(contents, I2(0x2e, 0x7e));
michael@0 873 }
michael@0 874
michael@0 875 TEST_F(Append, GeneralBE3) {
michael@0 876 section.Append(kBigEndian, 3, 0x37dad6ULL);
michael@0 877 ASSERT_TRUE(section.GetContents(&contents));
michael@0 878 ASSERT_BYTES(contents, I3(0x37, 0xda, 0xd6));
michael@0 879 }
michael@0 880
michael@0 881 TEST_F(Append, GeneralBE4) {
michael@0 882 section.Append(kBigEndian, 4, 0x715935c7ULL);
michael@0 883 ASSERT_TRUE(section.GetContents(&contents));
michael@0 884 ASSERT_BYTES(contents, I4(0x71, 0x59, 0x35, 0xc7));
michael@0 885 }
michael@0 886
michael@0 887 TEST_F(Append, GeneralBE5) {
michael@0 888 section.Append(kBigEndian, 5, 0x42baeb02b7ULL);
michael@0 889 ASSERT_TRUE(section.GetContents(&contents));
michael@0 890 ASSERT_BYTES(contents, I5(0x42, 0xba, 0xeb, 0x02, 0xb7));
michael@0 891 }
michael@0 892
michael@0 893 TEST_F(Append, GeneralBE6) {
michael@0 894 section.Append(kBigEndian, 6, 0xf1cdf10e7b18ULL);
michael@0 895 ASSERT_TRUE(section.GetContents(&contents));
michael@0 896 ASSERT_BYTES(contents, I6(0xf1, 0xcd, 0xf1, 0x0e, 0x7b, 0x18));
michael@0 897 }
michael@0 898
michael@0 899 TEST_F(Append, GeneralBE7) {
michael@0 900 section.Append(kBigEndian, 7, 0xf50a724f0b0d20ULL);
michael@0 901 ASSERT_TRUE(section.GetContents(&contents));
michael@0 902 ASSERT_BYTES(contents, I7(0xf5, 0x0a, 0x72, 0x4f, 0x0b, 0x0d, 0x20));
michael@0 903 }
michael@0 904
michael@0 905 TEST_F(Append, GeneralBE8) {
michael@0 906 section.Append(kBigEndian, 8, 0xa6b2cb5e98dc9c16ULL);
michael@0 907 ASSERT_TRUE(section.GetContents(&contents));
michael@0 908 ASSERT_BYTES(contents, I8(0xa6, 0xb2, 0xcb, 0x5e, 0x98, 0xdc, 0x9c, 0x16));
michael@0 909 }
michael@0 910
michael@0 911 TEST_F(Append, GeneralLE1Label) {
michael@0 912 Label l;
michael@0 913 section.Append(kLittleEndian, 1, l);
michael@0 914 l = 42;
michael@0 915 ASSERT_TRUE(section.GetContents(&contents));
michael@0 916 ASSERT_BYTES(contents, I1(42));
michael@0 917 }
michael@0 918
michael@0 919 TEST_F(Append, GeneralLE2Label) {
michael@0 920 Label l;
michael@0 921 section.Append(kLittleEndian, 2, l);
michael@0 922 l = 0x15a1;
michael@0 923 ASSERT_TRUE(section.GetContents(&contents));
michael@0 924 ASSERT_BYTES(contents, I2(0xa1, 0x15));
michael@0 925 }
michael@0 926
michael@0 927 TEST_F(Append, GeneralLE3Label) {
michael@0 928 Label l;
michael@0 929 section.Append(kLittleEndian, 3, l);
michael@0 930 l = 0x59ae8d;
michael@0 931 ASSERT_TRUE(section.GetContents(&contents));
michael@0 932 ASSERT_BYTES(contents, I3(0x8d, 0xae, 0x59));
michael@0 933 }
michael@0 934
michael@0 935 TEST_F(Append, GeneralLE4Label) {
michael@0 936 Label l;
michael@0 937 section.Append(kLittleEndian, 4, l);
michael@0 938 l = 0x51603c56;
michael@0 939 ASSERT_TRUE(section.GetContents(&contents));
michael@0 940 ASSERT_BYTES(contents, I4(0x56, 0x3c, 0x60, 0x51));
michael@0 941 }
michael@0 942
michael@0 943 TEST_F(Append, GeneralLE5Label) {
michael@0 944 Label l;
michael@0 945 section.Append(kLittleEndian, 5, l);
michael@0 946 l = 0x385e2803b4ULL;
michael@0 947 ASSERT_TRUE(section.GetContents(&contents));
michael@0 948 ASSERT_BYTES(contents, I5(0xb4, 0x03, 0x28, 0x5e, 0x38));
michael@0 949 }
michael@0 950
michael@0 951 TEST_F(Append, GeneralLE6Label) {
michael@0 952 Label l;
michael@0 953 section.Append(kLittleEndian, 6, l);
michael@0 954 l = 0xc7db9534dd1fULL;
michael@0 955 ASSERT_TRUE(section.GetContents(&contents));
michael@0 956 ASSERT_BYTES(contents, I6(0x1f, 0xdd, 0x34, 0x95, 0xdb, 0xc7));
michael@0 957 }
michael@0 958
michael@0 959 TEST_F(Append, GeneralLE7Label) {
michael@0 960 Label l;
michael@0 961 section.Append(kLittleEndian, 7, l);
michael@0 962 l = 0x1445c9f1b843e6ULL;
michael@0 963 ASSERT_TRUE(section.GetContents(&contents));
michael@0 964 ASSERT_BYTES(contents, I7(0xe6, 0x43, 0xb8, 0xf1, 0xc9, 0x45, 0x14));
michael@0 965 }
michael@0 966
michael@0 967 TEST_F(Append, GeneralLE8Label) {
michael@0 968 Label l;
michael@0 969 section.Append(kLittleEndian, 8, l);
michael@0 970 l = 0xaf48019dfe5c01e5ULL;
michael@0 971 ASSERT_TRUE(section.GetContents(&contents));
michael@0 972 ASSERT_BYTES(contents, I8(0xe5, 0x01, 0x5c, 0xfe, 0x9d, 0x01, 0x48, 0xaf));
michael@0 973 }
michael@0 974
michael@0 975 TEST_F(Append, GeneralBE1Label) {
michael@0 976 Label l;
michael@0 977 section.Append(kBigEndian, 1, l);
michael@0 978 l = 0xd0ULL;
michael@0 979 ASSERT_TRUE(section.GetContents(&contents));
michael@0 980 ASSERT_BYTES(contents, I1(0xd0));
michael@0 981 }
michael@0 982
michael@0 983 TEST_F(Append, GeneralBE2Label) {
michael@0 984 Label l;
michael@0 985 section.Append(kBigEndian, 2, l);
michael@0 986 l = 0x2e7eULL;
michael@0 987 ASSERT_TRUE(section.GetContents(&contents));
michael@0 988 ASSERT_BYTES(contents, I2(0x2e, 0x7e));
michael@0 989 }
michael@0 990
michael@0 991 TEST_F(Append, GeneralBE3Label) {
michael@0 992 Label l;
michael@0 993 section.Append(kBigEndian, 3, l);
michael@0 994 l = 0x37dad6ULL;
michael@0 995 ASSERT_TRUE(section.GetContents(&contents));
michael@0 996 ASSERT_BYTES(contents, I3(0x37, 0xda, 0xd6));
michael@0 997 }
michael@0 998
michael@0 999 TEST_F(Append, GeneralBE4Label) {
michael@0 1000 Label l;
michael@0 1001 section.Append(kBigEndian, 4, l);
michael@0 1002 l = 0x715935c7ULL;
michael@0 1003 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1004 ASSERT_BYTES(contents, I4(0x71, 0x59, 0x35, 0xc7));
michael@0 1005 }
michael@0 1006
michael@0 1007 TEST_F(Append, GeneralBE5Label) {
michael@0 1008 Label l;
michael@0 1009 section.Append(kBigEndian, 5, l);
michael@0 1010 l = 0x42baeb02b7ULL;
michael@0 1011 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1012 ASSERT_BYTES(contents, I5(0x42, 0xba, 0xeb, 0x02, 0xb7));
michael@0 1013 }
michael@0 1014
michael@0 1015 TEST_F(Append, GeneralBE6Label) {
michael@0 1016 Label l;
michael@0 1017 section.Append(kBigEndian, 6, l);
michael@0 1018 l = 0xf1cdf10e7b18ULL;
michael@0 1019 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1020 ASSERT_BYTES(contents, I6(0xf1, 0xcd, 0xf1, 0x0e, 0x7b, 0x18));
michael@0 1021 }
michael@0 1022
michael@0 1023 TEST_F(Append, GeneralBE7Label) {
michael@0 1024 Label l;
michael@0 1025 section.Append(kBigEndian, 7, l);
michael@0 1026 l = 0xf50a724f0b0d20ULL;
michael@0 1027 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1028 ASSERT_BYTES(contents, I7(0xf5, 0x0a, 0x72, 0x4f, 0x0b, 0x0d, 0x20));
michael@0 1029 }
michael@0 1030
michael@0 1031 TEST_F(Append, GeneralBE8Label) {
michael@0 1032 Label l;
michael@0 1033 section.Append(kBigEndian, 8, l);
michael@0 1034 l = 0xa6b2cb5e98dc9c16ULL;
michael@0 1035 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1036 ASSERT_BYTES(contents, I8(0xa6, 0xb2, 0xcb, 0x5e, 0x98, 0xdc, 0x9c, 0x16));
michael@0 1037 }
michael@0 1038
michael@0 1039 TEST_F(Append, B8) {
michael@0 1040 section.Append(1, 0x2a);
michael@0 1041 section.B8(0xd3U);
michael@0 1042 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1043 ASSERT_BYTES(contents, I2(0x2a, 0xd3));
michael@0 1044 }
michael@0 1045
michael@0 1046 TEST_F(Append, B8Label) {
michael@0 1047 Label l;
michael@0 1048 section.Append(1, 0x2a);
michael@0 1049 section.B8(l);
michael@0 1050 l = 0x4bU;
michael@0 1051 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1052 ASSERT_BYTES(contents, I2(0x2a, 0x4b));
michael@0 1053 }
michael@0 1054
michael@0 1055 TEST_F(Append, B16) {
michael@0 1056 section.Append(1, 0x2a);
michael@0 1057 section.B16(0x472aU);
michael@0 1058 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1059 ASSERT_BYTES(contents, I3(0x2a, 0x47, 0x2a));
michael@0 1060 }
michael@0 1061
michael@0 1062 TEST_F(Append, B16Label) {
michael@0 1063 Label l;
michael@0 1064 section.Append(1, 0x2a);
michael@0 1065 section.B16(l);
michael@0 1066 l = 0x55e8U;
michael@0 1067 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1068 ASSERT_BYTES(contents, I3(0x2a, 0x55, 0xe8));
michael@0 1069 }
michael@0 1070
michael@0 1071 TEST_F(Append, B32) {
michael@0 1072 section.Append(1, 0x2a);
michael@0 1073 section.B32(0xbd412cbcU);
michael@0 1074 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1075 ASSERT_BYTES(contents, I5(0x2a, 0xbd, 0x41, 0x2c, 0xbc));
michael@0 1076 }
michael@0 1077
michael@0 1078 TEST_F(Append, B32Label) {
michael@0 1079 Label l;
michael@0 1080 section.Append(1, 0x2a);
michael@0 1081 section.B32(l);
michael@0 1082 l = 0x208e37d5U;
michael@0 1083 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1084 ASSERT_BYTES(contents, I5(0x2a, 0x20, 0x8e, 0x37, 0xd5));
michael@0 1085 }
michael@0 1086
michael@0 1087 TEST_F(Append, B64) {
michael@0 1088 section.Append(1, 0x2a);
michael@0 1089 section.B64(0x3402a013111e68adULL);
michael@0 1090 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1091 ASSERT_BYTES(contents,
michael@0 1092 I9(0x2a, 0x34, 0x02, 0xa0, 0x13, 0x11, 0x1e, 0x68, 0xad));
michael@0 1093 }
michael@0 1094
michael@0 1095 TEST_F(Append, B64Label) {
michael@0 1096 Label l;
michael@0 1097 section.Append(1, 0x2a);
michael@0 1098 section.B64(l);
michael@0 1099 l = 0x355dbfbb4ac6d57fULL;
michael@0 1100 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1101 ASSERT_BYTES(contents,
michael@0 1102 I9(0x2a, 0x35, 0x5d, 0xbf, 0xbb, 0x4a, 0xc6, 0xd5, 0x7f));
michael@0 1103 }
michael@0 1104
michael@0 1105 TEST_F(Append, L8) {
michael@0 1106 section.Append(1, 0x2a);
michael@0 1107 section.L8(0x26U);
michael@0 1108 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1109 ASSERT_BYTES(contents, I2(0x2a, 0x26));
michael@0 1110 }
michael@0 1111
michael@0 1112 TEST_F(Append, L8Label) {
michael@0 1113 Label l;
michael@0 1114 section.Append(1, 0x2a);
michael@0 1115 section.L8(l);
michael@0 1116 l = 0xa8U;
michael@0 1117 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1118 ASSERT_BYTES(contents, I2(0x2a, 0xa8));
michael@0 1119 }
michael@0 1120
michael@0 1121 TEST_F(Append, L16) {
michael@0 1122 section.Append(1, 0x2a);
michael@0 1123 section.L16(0xca6dU);
michael@0 1124 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1125 ASSERT_BYTES(contents, I3(0x2a, 0x6d, 0xca));
michael@0 1126 }
michael@0 1127
michael@0 1128 TEST_F(Append, L16Label) {
michael@0 1129 Label l;
michael@0 1130 section.Append(1, 0x2a);
michael@0 1131 section.L16(l);
michael@0 1132 l = 0xd21fU;
michael@0 1133 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1134 ASSERT_BYTES(contents, I3(0x2a, 0x1f, 0xd2));
michael@0 1135 }
michael@0 1136
michael@0 1137 TEST_F(Append, L32) {
michael@0 1138 section.Append(1, 0x2a);
michael@0 1139 section.L32(0x558f6181U);
michael@0 1140 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1141 ASSERT_BYTES(contents, I5(0x2a, 0x81, 0x61, 0x8f, 0x55));
michael@0 1142 }
michael@0 1143
michael@0 1144 TEST_F(Append, L32Label) {
michael@0 1145 Label l;
michael@0 1146 section.Append(1, 0x2a);
michael@0 1147 section.L32(l);
michael@0 1148 l = 0x4b810f82U;
michael@0 1149 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1150 ASSERT_BYTES(contents, I5(0x2a, 0x82, 0x0f, 0x81, 0x4b));
michael@0 1151 }
michael@0 1152
michael@0 1153 TEST_F(Append, L64) {
michael@0 1154 section.Append(1, 0x2a);
michael@0 1155 section.L64(0x564384f7579515bfULL);
michael@0 1156 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1157 ASSERT_BYTES(contents,
michael@0 1158 I9(0x2a, 0xbf, 0x15, 0x95, 0x57, 0xf7, 0x84, 0x43, 0x56));
michael@0 1159 }
michael@0 1160
michael@0 1161 TEST_F(Append, L64Label) {
michael@0 1162 Label l;
michael@0 1163 section.Append(1, 0x2a);
michael@0 1164 section.L64(l);
michael@0 1165 l = 0x424b1d020667c8dbULL;
michael@0 1166 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1167 ASSERT_BYTES(contents,
michael@0 1168 I9(0x2a, 0xdb, 0xc8, 0x67, 0x06, 0x02, 0x1d, 0x4b, 0x42));
michael@0 1169 }
michael@0 1170
michael@0 1171 TEST_F(Append, D8Big) {
michael@0 1172 section.set_endianness(kBigEndian);
michael@0 1173 section.Append(1, 0x2a);
michael@0 1174 section.D8(0xe6U);
michael@0 1175 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1176 ASSERT_BYTES(contents, I2(0x2a, 0xe6));
michael@0 1177 }
michael@0 1178
michael@0 1179 TEST_F(Append, D8BigLabel) {
michael@0 1180 Label l;
michael@0 1181 section.set_endianness(kBigEndian);
michael@0 1182 section.Append(1, 0x2a);
michael@0 1183 section.D8(l);
michael@0 1184 l = 0xeeU;
michael@0 1185 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1186 ASSERT_BYTES(contents, I2(0x2a, 0xee));
michael@0 1187 }
michael@0 1188
michael@0 1189 TEST_F(Append, D16Big) {
michael@0 1190 section.set_endianness(kBigEndian);
michael@0 1191 section.Append(1, 0x2a);
michael@0 1192 section.D16(0x83b1U);
michael@0 1193 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1194 ASSERT_BYTES(contents, I3(0x2a, 0x83, 0xb1));
michael@0 1195 }
michael@0 1196
michael@0 1197 TEST_F(Append, D16BigLabel) {
michael@0 1198 Label l;
michael@0 1199 section.set_endianness(kBigEndian);
michael@0 1200 section.Append(1, 0x2a);
michael@0 1201 section.D16(l);
michael@0 1202 l = 0x5b55U;
michael@0 1203 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1204 ASSERT_BYTES(contents, I3(0x2a, 0x5b, 0x55));
michael@0 1205 }
michael@0 1206
michael@0 1207 TEST_F(Append, D32Big) {
michael@0 1208 section.set_endianness(kBigEndian);
michael@0 1209 section.Append(1, 0x2a);
michael@0 1210 section.D32(0xd0b0e431U);
michael@0 1211 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1212 ASSERT_BYTES(contents, I5(0x2a, 0xd0, 0xb0, 0xe4, 0x31));
michael@0 1213 }
michael@0 1214
michael@0 1215 TEST_F(Append, D32BigLabel) {
michael@0 1216 Label l;
michael@0 1217 section.set_endianness(kBigEndian);
michael@0 1218 section.Append(1, 0x2a);
michael@0 1219 section.D32(l);
michael@0 1220 l = 0x312fb340U;
michael@0 1221 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1222 ASSERT_BYTES(contents, I5(0x2a, 0x31, 0x2f, 0xb3, 0x40));
michael@0 1223 }
michael@0 1224
michael@0 1225 TEST_F(Append, D64Big) {
michael@0 1226 section.set_endianness(kBigEndian);
michael@0 1227 section.Append(1, 0x2a);
michael@0 1228 section.D64(0xb109843500dbcb16ULL);
michael@0 1229 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1230 ASSERT_BYTES(contents,
michael@0 1231 I9(0x2a, 0xb1, 0x09, 0x84, 0x35, 0x00, 0xdb, 0xcb, 0x16));
michael@0 1232 }
michael@0 1233
michael@0 1234 TEST_F(Append, D64BigLabel) {
michael@0 1235 Label l;
michael@0 1236 section.set_endianness(kBigEndian);
michael@0 1237 section.Append(1, 0x2a);
michael@0 1238 section.D64(l);
michael@0 1239 l = 0x9a0d61b70f671fd7ULL;
michael@0 1240 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1241 ASSERT_BYTES(contents,
michael@0 1242 I9(0x2a, 0x9a, 0x0d, 0x61, 0xb7, 0x0f, 0x67, 0x1f, 0xd7));
michael@0 1243 }
michael@0 1244
michael@0 1245 TEST_F(Append, D8Little) {
michael@0 1246 section.set_endianness(kLittleEndian);
michael@0 1247 section.Append(1, 0x2a);
michael@0 1248 section.D8(0x42U);
michael@0 1249 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1250 ASSERT_BYTES(contents, I2(0x2a, 0x42));
michael@0 1251 }
michael@0 1252
michael@0 1253 TEST_F(Append, D8LittleLabel) {
michael@0 1254 Label l;
michael@0 1255 section.set_endianness(kLittleEndian);
michael@0 1256 section.Append(1, 0x2a);
michael@0 1257 section.D8(l);
michael@0 1258 l = 0x05U;
michael@0 1259 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1260 ASSERT_BYTES(contents, I2(0x2a, 0x05));
michael@0 1261 }
michael@0 1262
michael@0 1263 TEST_F(Append, D16Little) {
michael@0 1264 section.set_endianness(kLittleEndian);
michael@0 1265 section.Append(1, 0x2a);
michael@0 1266 section.D16(0xc5c5U);
michael@0 1267 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1268 ASSERT_BYTES(contents, I3(0x2a, 0xc5, 0xc5));
michael@0 1269 }
michael@0 1270
michael@0 1271 TEST_F(Append, D16LittleLabel) {
michael@0 1272 Label l;
michael@0 1273 section.set_endianness(kLittleEndian);
michael@0 1274 section.Append(1, 0x2a);
michael@0 1275 section.D16(l);
michael@0 1276 l = 0xb620U;
michael@0 1277 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1278 ASSERT_BYTES(contents, I3(0x2a, 0x20, 0xb6));
michael@0 1279 }
michael@0 1280
michael@0 1281 TEST_F(Append, D32Little) {
michael@0 1282 section.set_endianness(kLittleEndian);
michael@0 1283 section.Append(1, 0x2a);
michael@0 1284 section.D32(0x1a87d0feU);
michael@0 1285 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1286 ASSERT_BYTES(contents, I5(0x2a, 0xfe, 0xd0, 0x87, 0x1a));
michael@0 1287 }
michael@0 1288
michael@0 1289 TEST_F(Append, D32LittleLabel) {
michael@0 1290 Label l;
michael@0 1291 section.set_endianness(kLittleEndian);
michael@0 1292 section.Append(1, 0x2a);
michael@0 1293 section.D32(l);
michael@0 1294 l = 0xb8012d6bU;
michael@0 1295 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1296 ASSERT_BYTES(contents, I5(0x2a, 0x6b, 0x2d, 0x01, 0xb8));
michael@0 1297 }
michael@0 1298
michael@0 1299 TEST_F(Append, D64Little) {
michael@0 1300 section.set_endianness(kLittleEndian);
michael@0 1301 section.Append(1, 0x2a);
michael@0 1302 section.D64(0x42de75c61375a1deULL);
michael@0 1303 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1304 ASSERT_BYTES(contents,
michael@0 1305 I9(0x2a, 0xde, 0xa1, 0x75, 0x13, 0xc6, 0x75, 0xde, 0x42));
michael@0 1306 }
michael@0 1307
michael@0 1308 TEST_F(Append, D64LittleLabel) {
michael@0 1309 Label l;
michael@0 1310 section.set_endianness(kLittleEndian);
michael@0 1311 section.Append(1, 0x2a);
michael@0 1312 section.D64(l);
michael@0 1313 l = 0x8b3bececf3fb5312ULL;
michael@0 1314 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1315 ASSERT_BYTES(contents,
michael@0 1316 I9(0x2a, 0x12, 0x53, 0xfb, 0xf3, 0xec, 0xec, 0x3b, 0x8b));
michael@0 1317 }
michael@0 1318
michael@0 1319 TEST_F(Append, Variety) {
michael@0 1320 Label a, b, c, d, e, f, g, h;
michael@0 1321 section.Append(kBigEndian, 1, a)
michael@0 1322 .Append(kLittleEndian, 8, h)
michael@0 1323 .Append(kBigEndian, 1, 0x8bULL)
michael@0 1324 .Append(kLittleEndian, 8, 0x0ea56540448f4439ULL)
michael@0 1325 .Append(kBigEndian, 2, b)
michael@0 1326 .Append(kLittleEndian, 7, g)
michael@0 1327 .Append(kBigEndian, 2, 0xcf15ULL)
michael@0 1328 .Append(kLittleEndian, 7, 0x29694f04c5724aULL)
michael@0 1329 .Append(kBigEndian, 3, c)
michael@0 1330 .Append(kLittleEndian, 6, f)
michael@0 1331 .Append(kBigEndian, 3, 0x8c3ffdULL)
michael@0 1332 .Append(kLittleEndian, 6, 0x6f11ba80187aULL)
michael@0 1333 .Append(kBigEndian, 4, d)
michael@0 1334 .Append(kLittleEndian, 5, e)
michael@0 1335 .Append(kBigEndian, 4, 0x2fda2472ULL)
michael@0 1336 .Append(kLittleEndian, 5, 0x0aa02d423fULL)
michael@0 1337 .Append(kBigEndian, 5, e)
michael@0 1338 .Append(kLittleEndian, 4, d)
michael@0 1339 .Append(kBigEndian, 5, 0x53ba432138ULL)
michael@0 1340 .Append(kLittleEndian, 4, 0xf139ae60ULL)
michael@0 1341 .Append(kBigEndian, 6, f)
michael@0 1342 .Append(kLittleEndian, 3, c)
michael@0 1343 .Append(kBigEndian, 6, 0x168e436af716ULL)
michael@0 1344 .Append(kLittleEndian, 3, 0x3ef189ULL)
michael@0 1345 .Append(kBigEndian, 7, g)
michael@0 1346 .Append(kLittleEndian, 2, b)
michael@0 1347 .Append(kBigEndian, 7, 0xacd4ef233e47d9ULL)
michael@0 1348 .Append(kLittleEndian, 2, 0x5311ULL)
michael@0 1349 .Append(kBigEndian, 8, h)
michael@0 1350 .Append(kLittleEndian, 1, a)
michael@0 1351 .Append(kBigEndian, 8, 0x4668d5f1c93637a1ULL)
michael@0 1352 .Append(kLittleEndian, 1, 0x65ULL);
michael@0 1353 a = 0x79ac9bd8aa256b35ULL;
michael@0 1354 b = 0x22d13097ef86c91cULL;
michael@0 1355 c = 0xf204968b0a05862fULL;
michael@0 1356 d = 0x163177f15a0eb4ecULL;
michael@0 1357 e = 0xbd1b0f1d977f2246ULL;
michael@0 1358 f = 0x2b0842eee83c6461ULL;
michael@0 1359 g = 0x92f4b928a4bf875eULL;
michael@0 1360 h = 0x61a199a8f7286ba6ULL;
michael@0 1361 ASSERT_EQ(8 * 18U, section.Size());
michael@0 1362 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1363
michael@0 1364 static const uint8_t expected[] = {
michael@0 1365 0x35, 0xa6, 0x6b, 0x28, 0xf7, 0xa8, 0x99, 0xa1, 0x61,
michael@0 1366 0x8b, 0x39, 0x44, 0x8f, 0x44, 0x40, 0x65, 0xa5, 0x0e,
michael@0 1367 0xc9, 0x1c, 0x5e, 0x87, 0xbf, 0xa4, 0x28, 0xb9, 0xf4,
michael@0 1368 0xcf, 0x15, 0x4a, 0x72, 0xc5, 0x04, 0x4f, 0x69, 0x29,
michael@0 1369 0x05, 0x86, 0x2f, 0x61, 0x64, 0x3c, 0xe8, 0xee, 0x42,
michael@0 1370 0x8c, 0x3f, 0xfd, 0x7a, 0x18, 0x80, 0xba, 0x11, 0x6f,
michael@0 1371 0x5a, 0x0e, 0xb4, 0xec, 0x46, 0x22, 0x7f, 0x97, 0x1d,
michael@0 1372 0x2f, 0xda, 0x24, 0x72, 0x3f, 0x42, 0x2d, 0xa0, 0x0a,
michael@0 1373 0x1d, 0x97, 0x7f, 0x22, 0x46, 0xec, 0xb4, 0x0e, 0x5a,
michael@0 1374 0x53, 0xba, 0x43, 0x21, 0x38, 0x60, 0xae, 0x39, 0xf1,
michael@0 1375 0x42, 0xee, 0xe8, 0x3c, 0x64, 0x61, 0x2f, 0x86, 0x05,
michael@0 1376 0x16, 0x8e, 0x43, 0x6a, 0xf7, 0x16, 0x89, 0xf1, 0x3e,
michael@0 1377 0xf4, 0xb9, 0x28, 0xa4, 0xbf, 0x87, 0x5e, 0x1c, 0xc9,
michael@0 1378 0xac, 0xd4, 0xef, 0x23, 0x3e, 0x47, 0xd9, 0x11, 0x53,
michael@0 1379 0x61, 0xa1, 0x99, 0xa8, 0xf7, 0x28, 0x6b, 0xa6, 0x35,
michael@0 1380 0x46, 0x68, 0xd5, 0xf1, 0xc9, 0x36, 0x37, 0xa1, 0x65,
michael@0 1381 };
michael@0 1382
michael@0 1383 ASSERT_TRUE(0 == memcmp(contents.data(), expected, sizeof(expected)));
michael@0 1384 }
michael@0 1385
michael@0 1386 TEST_F(Append, Section) {
michael@0 1387 section.Append("murder");
michael@0 1388 {
michael@0 1389 Section middle;
michael@0 1390 middle.Append(" she");
michael@0 1391 section.Append(middle);
michael@0 1392 }
michael@0 1393 section.Append(" wrote");
michael@0 1394 EXPECT_EQ(16U, section.Size());
michael@0 1395 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1396 EXPECT_STREQ(contents.c_str(), "murder she wrote");
michael@0 1397 }
michael@0 1398
michael@0 1399 TEST_F(Append, SectionRefs) {
michael@0 1400 section.Append("sugar ");
michael@0 1401 Label l;
michael@0 1402 {
michael@0 1403 Section middle;
michael@0 1404 Label m;
michael@0 1405 middle.B32(m);
michael@0 1406 section.Append(middle);
michael@0 1407 m = 0x66726565;
michael@0 1408 }
michael@0 1409 section.Append(" jazz");
michael@0 1410 EXPECT_EQ(15U, section.Size());
michael@0 1411 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1412 EXPECT_STREQ(contents.c_str(), "sugar free jazz");
michael@0 1413 }
michael@0 1414
michael@0 1415 TEST_F(Append, LEB128_0) {
michael@0 1416 section.LEB128(0);
michael@0 1417 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1418 EXPECT_EQ(string("\0", 1), contents);
michael@0 1419 }
michael@0 1420
michael@0 1421 TEST_F(Append, LEB128_0x3f) {
michael@0 1422 section.LEB128(0x3f);
michael@0 1423 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1424 EXPECT_EQ(string("\x3f", 1), contents);
michael@0 1425 }
michael@0 1426
michael@0 1427 TEST_F(Append, LEB128_0x40) {
michael@0 1428 section.LEB128(0x40);
michael@0 1429 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1430 EXPECT_EQ(string("\xc0\x00", 2), contents);
michael@0 1431 }
michael@0 1432
michael@0 1433 TEST_F(Append, LEB128_0x7f) {
michael@0 1434 section.LEB128(0x7f);
michael@0 1435 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1436 EXPECT_EQ(string("\xff\x00", 2), contents);
michael@0 1437 }
michael@0 1438
michael@0 1439 TEST_F(Append, LEB128_0x80) {
michael@0 1440 section.LEB128(0x80);
michael@0 1441 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1442 EXPECT_EQ(string("\x80\x01", 2), contents);
michael@0 1443 }
michael@0 1444
michael@0 1445 TEST_F(Append, LEB128_0xff) {
michael@0 1446 section.LEB128(0xff);
michael@0 1447 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1448 EXPECT_EQ(string("\xff\x01", 2), contents);
michael@0 1449 }
michael@0 1450
michael@0 1451 TEST_F(Append, LEB128_0x1fff) {
michael@0 1452 section.LEB128(0x1fff);
michael@0 1453 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1454 EXPECT_EQ(string("\xff\x3f", 2), contents);
michael@0 1455 }
michael@0 1456
michael@0 1457 TEST_F(Append, LEB128_0x2000) {
michael@0 1458 section.LEB128(0x2000);
michael@0 1459 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1460 EXPECT_EQ(string("\x80\xc0\x00", 3), contents);
michael@0 1461 }
michael@0 1462
michael@0 1463 TEST_F(Append, LEB128_n1) {
michael@0 1464 section.LEB128(-1);
michael@0 1465 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1466 EXPECT_EQ(string("\x7f", 1), contents);
michael@0 1467 }
michael@0 1468
michael@0 1469 TEST_F(Append, LEB128_n0x40) {
michael@0 1470 section.LEB128(-0x40);
michael@0 1471 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1472 EXPECT_EQ(string("\x40", 1), contents);
michael@0 1473 }
michael@0 1474
michael@0 1475 TEST_F(Append, LEB128_n0x41) {
michael@0 1476 section.LEB128(-0x41);
michael@0 1477 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1478 EXPECT_EQ(string("\xbf\x7f", 2), contents);
michael@0 1479 }
michael@0 1480
michael@0 1481 TEST_F(Append, LEB128_n0x7f) {
michael@0 1482 section.LEB128(-0x7f);
michael@0 1483 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1484 EXPECT_EQ(string("\x81\x7f", 2), contents);
michael@0 1485 }
michael@0 1486
michael@0 1487 TEST_F(Append, LEB128_n0x80) {
michael@0 1488 section.LEB128(-0x80);
michael@0 1489 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1490 EXPECT_EQ(string("\x80\x7f", 2), contents);
michael@0 1491 }
michael@0 1492
michael@0 1493 TEST_F(Append, LEB128_n0x2000) {
michael@0 1494 section.LEB128(-0x2000);
michael@0 1495 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1496 EXPECT_EQ(string("\x80\x40", 2), contents);
michael@0 1497 }
michael@0 1498
michael@0 1499 TEST_F(Append, LEB128_n0x2001) {
michael@0 1500 section.LEB128(-0x2001);
michael@0 1501 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1502 EXPECT_EQ(string("\xff\xbf\x7f", 3), contents);
michael@0 1503 }
michael@0 1504
michael@0 1505 TEST_F(Append,ULEB128_0) {
michael@0 1506 section.ULEB128(0);
michael@0 1507 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1508 EXPECT_EQ(string("\0", 1), contents);
michael@0 1509 }
michael@0 1510
michael@0 1511 TEST_F(Append,ULEB128_1) {
michael@0 1512 section.ULEB128(1);
michael@0 1513 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1514 EXPECT_EQ(string("\x01", 1), contents);
michael@0 1515 }
michael@0 1516
michael@0 1517 TEST_F(Append,ULEB128_0x3f) {
michael@0 1518 section.ULEB128(0x3f);
michael@0 1519 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1520 EXPECT_EQ(string("\x3f", 1), contents);
michael@0 1521 }
michael@0 1522
michael@0 1523 TEST_F(Append,ULEB128_0x40) {
michael@0 1524 section.ULEB128(0x40);
michael@0 1525 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1526 EXPECT_EQ(string("\x40", 1), contents);
michael@0 1527 }
michael@0 1528
michael@0 1529 TEST_F(Append,ULEB128_0x7f) {
michael@0 1530 section.ULEB128(0x7f);
michael@0 1531 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1532 EXPECT_EQ(string("\x7f", 1), contents);
michael@0 1533 }
michael@0 1534
michael@0 1535 TEST_F(Append,ULEB128_0x80) {
michael@0 1536 section.ULEB128(0x80);
michael@0 1537 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1538 EXPECT_EQ(string("\x80\x01", 2), contents);
michael@0 1539 }
michael@0 1540
michael@0 1541 TEST_F(Append,ULEB128_0xff) {
michael@0 1542 section.ULEB128(0xff);
michael@0 1543 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1544 EXPECT_EQ(string("\xff\x01", 2), contents);
michael@0 1545 }
michael@0 1546
michael@0 1547 TEST_F(Append,ULEB128_0x100) {
michael@0 1548 section.ULEB128(0x100);
michael@0 1549 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1550 EXPECT_EQ(string("\x80\x02", 2), contents);
michael@0 1551 }
michael@0 1552
michael@0 1553 TEST_F(Append,ULEB128_0x1fff) {
michael@0 1554 section.ULEB128(0x1fff);
michael@0 1555 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1556 EXPECT_EQ(string("\xff\x3f", 2), contents);
michael@0 1557 }
michael@0 1558
michael@0 1559 TEST_F(Append,ULEB128_0x2000) {
michael@0 1560 section.ULEB128(0x2000);
michael@0 1561 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1562 EXPECT_EQ(string("\x80\x40", 2), contents);
michael@0 1563 }
michael@0 1564
michael@0 1565 TEST_F(Append,ULEB128_0x3fff) {
michael@0 1566 section.ULEB128(0x3fff);
michael@0 1567 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1568 EXPECT_EQ(string("\xff\x7f", 2), contents);
michael@0 1569 }
michael@0 1570
michael@0 1571 TEST_F(Append,ULEB128_0x4000) {
michael@0 1572 section.ULEB128(0x4000);
michael@0 1573 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1574 EXPECT_EQ(string("\x80\x80\x01", 3), contents);
michael@0 1575 }
michael@0 1576
michael@0 1577 TEST_F(Append,ULEB128_12857) {
michael@0 1578 section.ULEB128(12857);
michael@0 1579 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1580 EXPECT_EQ(string("\xb9\x64", 2), contents);
michael@0 1581 }
michael@0 1582
michael@0 1583 TEST_F(Append, LEBChain) {
michael@0 1584 section.LEB128(-0x80).ULEB128(12857).Append("*");
michael@0 1585 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1586 EXPECT_EQ(string("\x80\x7f\xb9\x64*", 5), contents);
michael@0 1587 }
michael@0 1588
michael@0 1589
michael@0 1590 class GetContents: public SectionFixture, public Test { };
michael@0 1591
michael@0 1592 TEST_F(GetContents, Undefined) {
michael@0 1593 Label l;
michael@0 1594 section.Append(kLittleEndian, 8, l);
michael@0 1595 ASSERT_FALSE(section.GetContents(&contents));
michael@0 1596 }
michael@0 1597
michael@0 1598 TEST_F(GetContents, ClearsContents) {
michael@0 1599 section.Append((size_t) 10, '*');
michael@0 1600 EXPECT_EQ(10U, section.Size());
michael@0 1601 EXPECT_TRUE(section.GetContents(&contents));
michael@0 1602 EXPECT_EQ(0U, section.Size());
michael@0 1603 }
michael@0 1604
michael@0 1605 TEST_F(GetContents, ClearsReferences) {
michael@0 1606 Label l;
michael@0 1607 section.Append(kBigEndian, 1, l);
michael@0 1608 l = 42;
michael@0 1609 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1610 ASSERT_BYTES(contents, I1(42));
michael@0 1611 ASSERT_TRUE(section.GetContents(&contents)); // should not die
michael@0 1612 }
michael@0 1613
michael@0 1614 class Miscellanea: public SectionFixture, public Test { };
michael@0 1615
michael@0 1616 TEST_F(Miscellanea, Clear) {
michael@0 1617 section.Append("howdy");
michael@0 1618 Label l;
michael@0 1619 section.L32(l);
michael@0 1620 EXPECT_EQ(9U, section.Size());
michael@0 1621 section.Clear();
michael@0 1622 EXPECT_EQ(0U, section.Size());
michael@0 1623 l = 0x8d231bf0U;
michael@0 1624 ASSERT_TRUE(section.GetContents(&contents)); // should not die
michael@0 1625 }
michael@0 1626
michael@0 1627 TEST_F(Miscellanea, Align) {
michael@0 1628 section.Append("*");
michael@0 1629 EXPECT_EQ(1U, section.Size());
michael@0 1630 section.Align(4).Append("*");
michael@0 1631 EXPECT_EQ(5U, section.Size());
michael@0 1632 section.Append("*").Align(2);
michael@0 1633 EXPECT_EQ(6U, section.Size());
michael@0 1634 }
michael@0 1635
michael@0 1636 TEST_F(Miscellanea, AlignPad) {
michael@0 1637 section.Append("*");
michael@0 1638 EXPECT_EQ(1U, section.Size());
michael@0 1639 section.Align(4, ' ').Append("*");
michael@0 1640 EXPECT_EQ(5U, section.Size());
michael@0 1641 section.Append("*").Align(2, ' ');
michael@0 1642 EXPECT_EQ(6U, section.Size());
michael@0 1643 ASSERT_TRUE(section.GetContents(&contents));
michael@0 1644 ASSERT_EQ(string("* **"), contents);
michael@0 1645 }
michael@0 1646
michael@0 1647 TEST_F(Miscellanea, StartHereMark) {
michael@0 1648 Label m;
michael@0 1649 section.Append(42, ' ').Mark(&m).Append(13, '+');
michael@0 1650 EXPECT_EQ(42U, m - section.start());
michael@0 1651 EXPECT_EQ(42U + 13U, section.Here() - section.start());
michael@0 1652 EXPECT_FALSE(section.start().IsKnownConstant());
michael@0 1653 EXPECT_FALSE(m.IsKnownConstant());
michael@0 1654 EXPECT_FALSE(section.Here().IsKnownConstant());
michael@0 1655 }
michael@0 1656
michael@0 1657 TEST_F(Miscellanea, Endianness) {
michael@0 1658 section.set_endianness(kBigEndian);
michael@0 1659 EXPECT_EQ(kBigEndian, section.endianness());
michael@0 1660 section.set_endianness(kLittleEndian);
michael@0 1661 EXPECT_EQ(kLittleEndian, section.endianness());
michael@0 1662 }

mercurial