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

Side by Side Diff: test/cctest/test-unique.cc

Issue 23475038: Fix compile error with CLANG. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 18 matching lines...) Expand all
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "factory.h" 32 #include "factory.h"
33 #include "global-handles.h" 33 #include "global-handles.h"
34 #include "unique.h" 34 #include "unique.h"
35 #include "cctest.h" 35 #include "cctest.h"
36 36
37 using namespace v8::internal; 37 using namespace v8::internal;
38 38
39 template <class T, class U>
40 void CheckHashCodeEqual(Unique<T> a, Unique<U> b) {
41 int64_t hasha = static_cast<int64_t>(a.Hashcode());
42 int64_t hashb = static_cast<int64_t>(b.Hashcode());
43 CHECK_NE(static_cast<int64_t>(0), hasha);
44 CHECK_NE(static_cast<int64_t>(0), hashb);
45 CHECK_EQ(hasha, hashb);
46 }
47
48
49 template <class T, class U>
50 void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) {
51 int64_t hasha = static_cast<int64_t>(a.Hashcode());
52 int64_t hashb = static_cast<int64_t>(b.Hashcode());
53 CHECK_NE(static_cast<int64_t>(0), hasha);
54 CHECK_NE(static_cast<int64_t>(0), hashb);
55 CHECK_NE(hasha, hashb);
56 }
57
58
39 TEST(UniqueCreate) { 59 TEST(UniqueCreate) {
40 CcTest::InitializeVM(); 60 CcTest::InitializeVM();
41 Isolate* isolate = Isolate::Current(); 61 Isolate* isolate = Isolate::Current();
42 Factory* factory = isolate->factory(); 62 Factory* factory = isolate->factory();
43 HandleScope sc(isolate); 63 HandleScope sc(isolate);
44 64
45 Handle<String> A = factory->InternalizeUtf8String("A"); 65 Handle<String> A = factory->InternalizeUtf8String("A");
46 Unique<String> HA(A); 66 Unique<String> HA(A);
47 67
48 CHECK_NE(static_cast<intptr_t>(0), HA.Hashcode());
49 CHECK(*HA.handle() == *A); 68 CHECK(*HA.handle() == *A);
50 CHECK_EQ(*A, *HA.handle()); 69 CHECK_EQ(*A, *HA.handle());
51 70
52 Unique<String> HA2(A); 71 Unique<String> HA2(A);
53 72
54 CHECK_EQ(HA.Hashcode(), HA2.Hashcode()); 73 CheckHashCodeEqual(HA, HA2);
55 CHECK(HA == HA2); 74 CHECK(HA == HA2);
56 CHECK_EQ(*HA.handle(), *HA2.handle()); 75 CHECK_EQ(*HA.handle(), *HA2.handle());
57 76
58 CHECK_EQ(HA2.Hashcode(), HA.Hashcode());
59 CHECK(HA2 == HA); 77 CHECK(HA2 == HA);
60 CHECK_EQ(*HA2.handle(), *HA.handle()); 78 CHECK_EQ(*HA2.handle(), *HA.handle());
61 79
62 Handle<String> B = factory->InternalizeUtf8String("B"); 80 Handle<String> B = factory->InternalizeUtf8String("B");
63 Unique<String> HB(B); 81 Unique<String> HB(B);
64 82
65 CHECK_NE(HA.Hashcode(), HB.Hashcode()); 83 CheckHashCodeNotEqual(HA, HB);
66 CHECK(HA != HB); 84 CHECK(HA != HB);
67 CHECK_NE(*HA.handle(), *HB.handle()); 85 CHECK_NE(*HA.handle(), *HB.handle());
68 86
69 CHECK_NE(HB.Hashcode(), HA.Hashcode());
70 CHECK(HB != HA); 87 CHECK(HB != HA);
71 CHECK_NE(*HB.handle(), *HA.handle()); 88 CHECK_NE(*HB.handle(), *HA.handle());
72 89
73 // TODO(titzer): check that Unique properly survives a GC. 90 // TODO(titzer): check that Unique properly survives a GC.
74 } 91 }
75 92
76 93
77 TEST(UniqueSubsume) { 94 TEST(UniqueSubsume) {
78 CcTest::InitializeVM(); 95 CcTest::InitializeVM();
79 Isolate* isolate = Isolate::Current(); 96 Isolate* isolate = Isolate::Current();
80 Factory* factory = isolate->factory(); 97 Factory* factory = isolate->factory();
81 HandleScope sc(isolate); 98 HandleScope sc(isolate);
82 99
83 Handle<String> A = factory->InternalizeUtf8String("A"); 100 Handle<String> A = factory->InternalizeUtf8String("A");
84 Unique<String> HA(A); 101 Unique<String> HA(A);
85 102
86 CHECK_NE(static_cast<intptr_t>(0), HA.Hashcode());
87 CHECK(*HA.handle() == *A); 103 CHECK(*HA.handle() == *A);
88 CHECK_EQ(*A, *HA.handle()); 104 CHECK_EQ(*A, *HA.handle());
89 105
90 Unique<Object> HO = HA; // Here comes the subsumption, boys. 106 Unique<Object> HO = HA; // Here comes the subsumption, boys.
91 107
92 CHECK_EQ(HA.Hashcode(), HO.Hashcode()); 108 CheckHashCodeEqual(HA, HO);
93 CHECK(HA == HO); 109 CHECK(HA == HO);
94 CHECK_EQ(*HA.handle(), *HO.handle()); 110 CHECK_EQ(*HA.handle(), *HO.handle());
95 111
96 CHECK_EQ(HO.Hashcode(), HA.Hashcode());
97 CHECK(HO == HA); 112 CHECK(HO == HA);
98 CHECK_EQ(*HO.handle(), *HA.handle()); 113 CHECK_EQ(*HO.handle(), *HA.handle());
99 } 114 }
100 115
101 116
102 TEST(UniqueSet_Add) { 117 TEST(UniqueSet_Add) {
103 CcTest::InitializeVM(); 118 CcTest::InitializeVM();
104 Isolate* isolate = Isolate::Current(); 119 Isolate* isolate = Isolate::Current();
105 Factory* factory = isolate->factory(); 120 Factory* factory = isolate->factory();
106 HandleScope sc(isolate); 121 HandleScope sc(isolate);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 479
465 UniqueSet<String>* result = set1->Union(set2, &zone); 480 UniqueSet<String>* result = set1->Union(set2, &zone);
466 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements); 481 UniqueSet<String>* expected = MakeSet(&zone, i | j, elements);
467 482
468 CHECK(result->Equals(expected)); 483 CHECK(result->Equals(expected));
469 CHECK(expected->Equals(result)); 484 CHECK(expected->Equals(result));
470 } 485 }
471 } 486 }
472 } 487 }
473 488
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698