37 using namespace v8::internal;
39 #define MAKE_HANDLES_AND_DISALLOW_ALLOCATION \
40 Isolate* isolate = CcTest::i_isolate(); \
41 Factory* factory = isolate->factory(); \
42 HandleScope sc(isolate); \
43 Handle<String> handles[] = { \
44 factory->InternalizeUtf8String("A"), \
45 factory->InternalizeUtf8String("B"), \
46 factory->InternalizeUtf8String("C"), \
47 factory->InternalizeUtf8String("D"), \
48 factory->InternalizeUtf8String("E"), \
49 factory->InternalizeUtf8String("F"), \
50 factory->InternalizeUtf8String("G") \
52 DisallowHeapAllocation _disable
54 #define MAKE_UNIQUES_A_B_C \
55 Unique<String> A(handles[0]); \
56 Unique<String> B(handles[1]); \
57 Unique<String> C(handles[2])
59 #define MAKE_UNIQUES_A_B_C_D_E_F_G \
60 Unique<String> A(handles[0]); \
61 Unique<String> B(handles[1]); \
62 Unique<String> C(handles[2]); \
63 Unique<String> D(handles[3]); \
64 Unique<String> E(handles[4]); \
65 Unique<String> F(handles[5]); \
66 Unique<String> G(handles[6])
68 template <
class T,
class U>
70 int64_t hasha =
static_cast<int64_t
>(a.Hashcode());
71 int64_t hashb =
static_cast<int64_t
>(b.Hashcode());
72 CHECK_NE(static_cast<int64_t>(0), hasha);
73 CHECK_NE(static_cast<int64_t>(0), hashb);
78 template <
class T,
class U>
80 int64_t hasha =
static_cast<int64_t
>(a.Hashcode());
81 int64_t hashb =
static_cast<int64_t
>(b.Hashcode());
82 CHECK_NE(static_cast<int64_t>(0), hasha);
83 CHECK_NE(static_cast<int64_t>(0), hashb);
98 Unique<String> HA2(A);
102 CHECK_EQ(*HA.handle(), *HA2.handle());
105 CHECK_EQ(*HA2.handle(), *HA.handle());
107 Unique<String> HB(B);
111 CHECK_NE(*HA.handle(), *HB.handle());
114 CHECK_NE(*HB.handle(), *HA.handle());
125 Unique<String> HA(A);
127 CHECK(*HA.handle() == *
A);
130 Unique<Object> HO = HA;
134 CHECK_EQ(*HA.handle(), *HO.handle());
137 CHECK_EQ(*HO.handle(), *HA.handle());
186 CHECK(set->Contains(C));
192 CHECK(set->Contains(C));
198 CHECK(set->Contains(C));
204 CHECK(!set->Contains(C));
221 CHECK(!set->Contains(C));
226 CHECK(!set->Contains(C));
235 CHECK(set->Contains(C));
256 CHECK(
A == set->at(0) ||
B == set->at(0));
257 CHECK(
A == set->at(1) ||
B == set->at(1));
260 CHECK(
A == set->at(0) ||
B == set->at(0) || C == set->at(0));
261 CHECK(
A == set->at(1) ||
B == set->at(1) || C == set->at(1));
262 CHECK(
A == set->at(2) ||
B == set->at(2) || C == set->at(2));
267 static void CHECK_SETS(
269 CHECK(set1->Equals(set1));
270 CHECK(set2->Equals(set2));
271 CHECK(expected == set1->Equals(set2));
272 CHECK(expected == set2->Equals(set1));
286 CHECK_SETS(set1, set2,
true);
290 CHECK_SETS(set1, set2,
false);
294 CHECK_SETS(set1, set2,
true);
298 CHECK_SETS(set1, set2,
false);
302 CHECK_SETS(set1, set2,
false);
306 CHECK_SETS(set1, set2,
false);
310 CHECK_SETS(set1, set2,
true);
324 CHECK(set1->IsSubset(set2));
325 CHECK(set2->IsSubset(set1));
329 CHECK(!set1->IsSubset(set2));
330 CHECK(set2->IsSubset(set1));
334 CHECK(!set1->IsSubset(set2));
335 CHECK(!set2->IsSubset(set1));
339 CHECK(set1->IsSubset(set2));
340 CHECK(!set2->IsSubset(set1));
344 CHECK(set1->IsSubset(set2));
345 CHECK(set2->IsSubset(set1));
370 CHECK(set1->IsSubset(set2));
371 CHECK(!set2->IsSubset(set1));
375 CHECK(!set1->IsSubset(set2));
376 CHECK(!set2->IsSubset(set1));
383 for (
int i = 0; i < 32; i++) {
384 if ((which & (1 << i)) != 0) set->Add(elements[i], zone);
390 TEST(UniqueSet_IsSubsetExhaustive) {
391 const int kSetSize = 6;
399 Unique<String> elements[] = {
404 for (
int i = 0; i < (1 << kSetSize); i++) {
405 for (
int j = 0; j < (1 << kSetSize); j++) {
409 CHECK(((i & j) == i) == set1->IsSubset(set2));
426 CHECK(set1->IsSubset(set2));
427 CHECK(set2->IsSubset(set1));
431 result = set1->Intersect(set2, &zone);
434 CHECK(set2->Equals(result));
438 result = set1->Intersect(set2, &zone);
441 CHECK(set1->Equals(result));
442 CHECK(set2->Equals(result));
447 result = set1->Intersect(set2, &zone);
450 CHECK(set1->Equals(result));
454 TEST(UniqueSet_IntersectExhaustive) {
455 const int kSetSize = 6;
463 Unique<String> elements[] = {
468 for (
int i = 0; i < (1 << kSetSize); i++) {
469 for (
int j = 0; j < (1 << kSetSize); j++) {
476 CHECK(result->Equals(expected));
477 CHECK(expected->Equals(result));
494 CHECK(set1->IsSubset(set2));
495 CHECK(set2->IsSubset(set1));
499 result = set1->Union(set2, &zone);
502 CHECK(set1->Equals(result));
506 result = set1->Union(set2, &zone);
509 CHECK(set1->Equals(result));
510 CHECK(set2->Equals(result));
515 result = set1->Union(set2, &zone);
518 CHECK(set2->Equals(result));
522 TEST(UniqueSet_UnionExhaustive) {
523 const int kSetSize = 6;
531 Unique<String> elements[] = {
536 for (
int i = 0; i < (1 << kSetSize); i++) {
537 for (
int j = 0; j < (1 << kSetSize); j++) {
544 CHECK(result->Equals(expected));
545 CHECK(expected->Equals(result));
#define CHECK_EQ(expected, value)
#define MAKE_UNIQUES_A_B_C
#define MAKE_UNIQUES_A_B_C_D_E_F_G
void CheckHashCodeEqual(Unique< T > a, Unique< U > b)
void CheckHashCodeNotEqual(Unique< T > a, Unique< U > b)
#define CHECK_NE(unexpected, value)
static void InitializeVM()
#define MAKE_HANDLES_AND_DISALLOW_ALLOCATION