Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / v8 / test / cctest / test-dataflow.cc
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include <stdlib.h>
29
30 #include "src/v8.h"
31
32 #include "src/data-flow.h"
33 #include "test/cctest/cctest.h"
34
35 using namespace v8::internal;
36
37 TEST(BitVector) {
38   Zone zone(CcTest::i_isolate());
39   {
40     BitVector v(15, &zone);
41     v.Add(1);
42     CHECK(v.Contains(1));
43     v.Remove(0);
44     CHECK(!v.Contains(0));
45     v.Add(0);
46     v.Add(1);
47     BitVector w(15, &zone);
48     w.Add(1);
49     v.Intersect(w);
50     CHECK(!v.Contains(0));
51     CHECK(v.Contains(1));
52   }
53
54   {
55     BitVector v(64, &zone);
56     v.Add(27);
57     v.Add(30);
58     v.Add(31);
59     v.Add(33);
60     BitVector::Iterator iter(&v);
61     CHECK_EQ(27, iter.Current());
62     iter.Advance();
63     CHECK_EQ(30, iter.Current());
64     iter.Advance();
65     CHECK_EQ(31, iter.Current());
66     iter.Advance();
67     CHECK_EQ(33, iter.Current());
68     iter.Advance();
69     CHECK(iter.Done());
70   }
71
72   {
73     BitVector v(15, &zone);
74     v.Add(0);
75     BitVector w(15, &zone);
76     w.Add(1);
77     v.Union(w);
78     CHECK(v.Contains(0));
79     CHECK(v.Contains(1));
80   }
81
82   {
83     BitVector v(15, &zone);
84     v.Add(0);
85     BitVector w(15, &zone);
86     w = v;
87     CHECK(w.Contains(0));
88     w.Add(1);
89     BitVector u(w, &zone);
90     CHECK(u.Contains(0));
91     CHECK(u.Contains(1));
92     v.Union(w);
93     CHECK(v.Contains(0));
94     CHECK(v.Contains(1));
95   }
96
97   {
98     BitVector v(35, &zone);
99     v.Add(0);
100     BitVector w(35, &zone);
101     w.Add(33);
102     v.Union(w);
103     CHECK(v.Contains(0));
104     CHECK(v.Contains(33));
105   }
106
107   {
108     BitVector v(35, &zone);
109     v.Add(32);
110     v.Add(33);
111     BitVector w(35, &zone);
112     w.Add(33);
113     v.Intersect(w);
114     CHECK(!v.Contains(32));
115     CHECK(v.Contains(33));
116     BitVector r(35, &zone);
117     r.CopyFrom(v);
118     CHECK(!r.Contains(32));
119     CHECK(r.Contains(33));
120   }
121 }