Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / preprocessor_tests / input_test.cpp
1 //
2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 #include "PreprocessorTest.h"
8 #include "Input.h"
9 #include "Token.h"
10
11 class InitTest : public PreprocessorTest
12 {
13 };
14
15 TEST_F(InitTest, ZeroCount)
16 {
17     EXPECT_TRUE(mPreprocessor.init(0, NULL, NULL));
18
19     pp::Token token;
20     mPreprocessor.lex(&token);
21     EXPECT_EQ(pp::Token::LAST, token.type);
22 }
23
24 TEST_F(InitTest, NullString)
25 {
26     EXPECT_FALSE(mPreprocessor.init(1, NULL, NULL));
27 }
28
29 TEST(InputTest, DefaultConstructor)
30 {
31     pp::Input input;
32     EXPECT_EQ(0u, input.count());
33     EXPECT_EQ(0u, input.read(NULL, 1));
34 }
35
36 TEST(InputTest, NullLength)
37 {
38     const char* str[] = {"foo"};
39     pp::Input input(1, str, NULL);
40     EXPECT_EQ(3u, input.length(0));
41 }
42
43 TEST(InputTest, NegativeLength)
44 {
45     const char* str[] = {"foo"};
46     int length[] = {-1};
47     pp::Input input(1, str, length);
48     EXPECT_EQ(3u, input.length(0));
49 }
50
51 TEST(InputTest, ActualLength)
52 {
53     const char* str[] = {"foobar"};
54     int length[] = {3};
55     pp::Input input(1, str, length);
56     // Note that strlen(str[0]) != length[0].
57     // Even then Input should just accept any non-negative number.
58     EXPECT_EQ(static_cast<size_t>(length[0]), input.length(0));
59 }
60
61 TEST(InputTest, String)
62 {
63     const char* str[] = {"foo"};
64     pp::Input input(1, str, NULL);
65     EXPECT_STREQ(str[0], input.string(0));
66 }
67
68 TEST(InputTest, ReadSingleString)
69 {
70     int count = 1;
71     const char* str[] = {"foo"};
72     char buf[4] = {'\0', '\0', '\0', '\0'};
73
74     int maxSize = 1;
75     pp::Input input1(count, str, NULL);
76     EXPECT_EQ(1u, input1.read(buf, maxSize));
77     EXPECT_EQ('f', buf[0]);
78     EXPECT_EQ(1u, input1.read(buf, maxSize));
79     EXPECT_EQ('o', buf[0]);
80     EXPECT_EQ(1u, input1.read(buf, maxSize));
81     EXPECT_EQ('o', buf[0]);
82     EXPECT_EQ(0u, input1.read(buf, maxSize));
83
84     maxSize = 2;
85     pp::Input input2(count, str, NULL);
86     EXPECT_EQ(2u, input2.read(buf, maxSize));
87     EXPECT_STREQ("fo", buf);
88     EXPECT_EQ(1u, input2.read(buf, maxSize));
89     EXPECT_EQ('o', buf[0]);
90     EXPECT_EQ(0u, input2.read(buf, maxSize));
91
92     maxSize = 3;
93     pp::Input input3(count, str, NULL);
94     EXPECT_EQ(3u, input3.read(buf, maxSize));
95     EXPECT_STREQ("foo", buf);
96     EXPECT_EQ(0u, input3.read(buf, maxSize));
97
98     maxSize = 4;
99     pp::Input input4(count, str, NULL);
100     EXPECT_EQ(3u, input4.read(buf, maxSize));
101     EXPECT_STREQ("foo", buf);
102     EXPECT_EQ(0u, input4.read(buf, maxSize));
103 }
104
105 TEST(InputTest, ReadMultipleStrings)
106 {
107     int count = 3;
108     const char* str[] = {"f", "o", "o"};
109     char buf[4] = {'\0', '\0', '\0', '\0'};
110
111     int maxSize = 1;
112     pp::Input input1(count, str, NULL);
113     EXPECT_EQ(1u, input1.read(buf, maxSize));
114     EXPECT_EQ('f', buf[0]);
115     EXPECT_EQ(1u, input1.read(buf, maxSize));
116     EXPECT_EQ('o', buf[0]);
117     EXPECT_EQ(1u, input1.read(buf, maxSize));
118     EXPECT_EQ('o', buf[0]);
119     EXPECT_EQ(0u, input1.read(buf, maxSize));
120
121     maxSize = 2;
122     pp::Input input2(count, str, NULL);
123     EXPECT_EQ(2u, input2.read(buf, maxSize));
124     EXPECT_STREQ("fo", buf);
125     EXPECT_EQ(1u, input2.read(buf, maxSize));
126     EXPECT_EQ('o', buf[0]);
127     EXPECT_EQ(0u, input2.read(buf, maxSize));
128
129     maxSize = 3;
130     pp::Input input3(count, str, NULL);
131     EXPECT_EQ(3u, input3.read(buf, maxSize));
132     EXPECT_STREQ("foo", buf);
133     EXPECT_EQ(0u, input3.read(buf, maxSize));
134
135     maxSize = 4;
136     pp::Input input4(count, str, NULL);
137     EXPECT_EQ(3u, input4.read(buf, maxSize));
138     EXPECT_STREQ("foo", buf);
139     EXPECT_EQ(0u, input4.read(buf, maxSize));
140 }
141
142 TEST(InputTest, ReadStringsWithLength)
143 {
144     int count = 2;
145     const char* str[] = {"foo", "bar"};
146     // Note that the length for the first string is 2 which is less than
147     // strlen(str[0]. We want to make sure that the last character is ignored.
148     int length[] = {2, 3};
149     char buf[6] = {'\0', '\0', '\0', '\0', '\0', '\0'};
150     size_t maxSize = 5;
151
152     pp::Input input(count, str, length);
153     EXPECT_EQ(maxSize, input.read(buf, maxSize));
154     EXPECT_STREQ("fobar", buf);
155 }
156