Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: src/trusted/validator_mips/address_set_test.cc

Issue 9979025: [MIPS] Adding validator for MIPS architecture. (Closed) Base URL: http://src.chromium.org/native_client/trunk/src/native_client/
Patch Set: Rebased patch, conflict resolved. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/trusted/validator_mips/address_set.cc ('k') | src/trusted/validator_mips/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file.
5 * Copyright 2012, Google Inc.
6 */
7
8 /*
9 * A simple test for AddressSet.
10 */
11
12 #include <vector>
13 #include <string>
14 #include <sstream>
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 #include "gtest/gtest.h"
19 #include "native_client/src/include/nacl_macros.h"
20 #include "native_client/src/include/portability.h"
21 #include "native_client/src/trusted/validator_mips/address_set.h"
22
23 using nacl_mips_val::AddressSet;
24
25
26 class AddressTests : public ::testing::Test {
27 };
28
29 TEST_F(AddressTests, TestMutation) {
30 uint32_t base = 0x1234;
31 uint32_t size = 0x1000;
32 AddressSet as(base, size);
33
34 as.Add(0x1200); // Becomes a no-op.
35 as.Add(base + (31 * 4)); // Added.
36 as.Add(0x1240); // Added.
37 as.Add(0x1230); // No-op.
38 as.Add(base + size); // No-op.
39 as.Add(0x1235); // Added as 1234.
40 as.Add(0x1238); // Added.
41 as.Add(0x2000); // Added.
42 as.Add(base + size + 100); // No-op.
43 as.Add(0x1400); // Added.
44
45 // Successful additions in ascending order:
46 uint32_t expected[] = { 0x1234, 0x1238, 0x1240, base+(31*4), 0x1400, 0x2000 };
47 for (uint32_t i = 0; i < NACL_ARRAY_SIZE(expected); i++) {
48 EXPECT_TRUE(as.Contains(expected[i])) << "Set should contain "
49 << std::hex << expected[i]
50 << ", does not.";
51 }
52
53 uint32_t x = 0;
54 for (AddressSet::Iterator it = as.Begin(); !it.Equals(as.End());
55 it.Next(), ++x) {
56 EXPECT_EQ(it.GetAddress(), expected[x]) << "At " << x
57 << "\n Expected: " << std::hex
58 << expected[x]
59 << "\n Actual: " << std::hex
60 << it.GetAddress();
61 }
62 EXPECT_EQ(x, NACL_ARRAY_SIZE(expected)) << "Expected iterator to step"
63 << NACL_ARRAY_SIZE(expected)
64 << " times \n" << "Actual: " << x;
65
66 // Unsuccessful additions:
67 uint32_t unexpected[] = { 0x1200, 0x1230, base+size, base+size+100 };
68 for (uint32_t i = 0; i < NACL_ARRAY_SIZE(unexpected); i++) {
69 EXPECT_FALSE(as.Contains(unexpected[i])) << "Set should not contain "
70 << std::hex << unexpected[i];
71 }
72 }
73
74 int main(int argc, char *argv[]) {
75 testing::InitGoogleTest(&argc, argv);
76 return RUN_ALL_TESTS();
77 }
OLDNEW
« no previous file with comments | « src/trusted/validator_mips/address_set.cc ('k') | src/trusted/validator_mips/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698