Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / v8 / test / cctest / test-representation.cc
1 // Copyright 2013 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 "test/cctest/cctest.h"
29
30 #include "src/property-details.h"
31 #include "src/types.h"
32
33 using namespace v8::internal;
34
35
36 void TestPairPositive(Representation more_general,
37               Representation less_general) {
38   CHECK(more_general.is_more_general_than(less_general));
39 }
40
41
42 void TestPairNegative(Representation more_general,
43               Representation less_general) {
44   CHECK(!more_general.is_more_general_than(less_general));
45 }
46
47
48 TEST(RepresentationMoreGeneralThan) {
49   TestPairNegative(Representation::None(), Representation::None());
50   TestPairPositive(Representation::Integer8(), Representation::None());
51   TestPairPositive(Representation::UInteger8(), Representation::None());
52   TestPairPositive(Representation::Integer16(), Representation::None());
53   TestPairPositive(Representation::UInteger16(), Representation::None());
54   TestPairPositive(Representation::Smi(), Representation::None());
55   TestPairPositive(Representation::Integer32(), Representation::None());
56   TestPairPositive(Representation::HeapObject(), Representation::None());
57   TestPairPositive(Representation::Double(), Representation::None());
58   TestPairPositive(Representation::Tagged(), Representation::None());
59
60   TestPairNegative(Representation::None(), Representation::Integer8());
61   TestPairNegative(Representation::Integer8(), Representation::Integer8());
62   TestPairNegative(Representation::UInteger8(), Representation::Integer8());
63   TestPairPositive(Representation::Integer16(), Representation::Integer8());
64   TestPairPositive(Representation::UInteger16(), Representation::Integer8());
65   TestPairPositive(Representation::Smi(), Representation::Integer8());
66   TestPairPositive(Representation::Integer32(), Representation::Integer8());
67   TestPairNegative(Representation::HeapObject(), Representation::Integer8());
68   TestPairPositive(Representation::Double(), Representation::Integer8());
69   TestPairPositive(Representation::Tagged(), Representation::Integer8());
70
71   TestPairNegative(Representation::None(), Representation::UInteger8());
72   TestPairNegative(Representation::Integer8(), Representation::UInteger8());
73   TestPairNegative(Representation::UInteger8(), Representation::UInteger8());
74   TestPairPositive(Representation::Integer16(), Representation::UInteger8());
75   TestPairPositive(Representation::UInteger16(), Representation::UInteger8());
76   TestPairPositive(Representation::Smi(), Representation::UInteger8());
77   TestPairPositive(Representation::Integer32(), Representation::UInteger8());
78   TestPairNegative(Representation::HeapObject(), Representation::UInteger8());
79   TestPairPositive(Representation::Double(), Representation::UInteger8());
80   TestPairPositive(Representation::Tagged(), Representation::UInteger8());
81
82   TestPairNegative(Representation::None(), Representation::Integer16());
83   TestPairNegative(Representation::Integer8(), Representation::Integer16());
84   TestPairNegative(Representation::UInteger8(), Representation::Integer16());
85   TestPairNegative(Representation::Integer16(), Representation::Integer16());
86   TestPairNegative(Representation::UInteger16(), Representation::Integer16());
87   TestPairPositive(Representation::Smi(), Representation::Integer16());
88   TestPairPositive(Representation::Integer32(), Representation::Integer16());
89   TestPairNegative(Representation::HeapObject(), Representation::Integer16());
90   TestPairPositive(Representation::Double(), Representation::Integer16());
91   TestPairPositive(Representation::Tagged(), Representation::Integer16());
92
93   TestPairNegative(Representation::None(), Representation::UInteger16());
94   TestPairNegative(Representation::Integer8(), Representation::UInteger16());
95   TestPairNegative(Representation::UInteger8(), Representation::UInteger16());
96   TestPairNegative(Representation::Integer16(), Representation::UInteger16());
97   TestPairNegative(Representation::UInteger16(), Representation::UInteger16());
98   TestPairPositive(Representation::Smi(), Representation::UInteger16());
99   TestPairPositive(Representation::Integer32(), Representation::UInteger16());
100   TestPairNegative(Representation::HeapObject(), Representation::UInteger16());
101   TestPairPositive(Representation::Double(), Representation::UInteger16());
102   TestPairPositive(Representation::Tagged(), Representation::UInteger16());
103
104   TestPairNegative(Representation::None(), Representation::Smi());
105   TestPairNegative(Representation::Integer8(), Representation::Smi());
106   TestPairNegative(Representation::UInteger8(), Representation::Smi());
107   TestPairNegative(Representation::Integer16(), Representation::Smi());
108   TestPairNegative(Representation::UInteger16(), Representation::Smi());
109   TestPairNegative(Representation::Smi(), Representation::Smi());
110   TestPairPositive(Representation::Integer32(), Representation::Smi());
111   TestPairNegative(Representation::HeapObject(), Representation::Smi());
112   TestPairPositive(Representation::Double(), Representation::Smi());
113   TestPairPositive(Representation::Tagged(), Representation::Smi());
114
115   TestPairNegative(Representation::None(), Representation::Integer32());
116   TestPairNegative(Representation::Integer8(), Representation::Integer32());
117   TestPairNegative(Representation::UInteger8(), Representation::Integer32());
118   TestPairNegative(Representation::Integer16(), Representation::Integer32());
119   TestPairNegative(Representation::UInteger16(), Representation::Integer32());
120   TestPairNegative(Representation::Smi(), Representation::Integer32());
121   TestPairNegative(Representation::Integer32(), Representation::Integer32());
122   TestPairNegative(Representation::HeapObject(), Representation::Integer32());
123   TestPairPositive(Representation::Double(), Representation::Integer32());
124   TestPairPositive(Representation::Tagged(), Representation::Integer32());
125
126   TestPairNegative(Representation::None(), Representation::External());
127   TestPairNegative(Representation::External(), Representation::External());
128   TestPairPositive(Representation::External(), Representation::None());
129 }