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.
7 #include "PreprocessorTest.h"
11 class InitTest : public PreprocessorTest
15 TEST_F(InitTest, ZeroCount)
17 EXPECT_TRUE(mPreprocessor.init(0, NULL, NULL));
20 mPreprocessor.lex(&token);
21 EXPECT_EQ(pp::Token::LAST, token.type);
24 TEST_F(InitTest, NullString)
26 EXPECT_FALSE(mPreprocessor.init(1, NULL, NULL));
29 TEST(InputTest, DefaultConstructor)
32 EXPECT_EQ(0u, input.count());
33 EXPECT_EQ(0u, input.read(NULL, 1));
36 TEST(InputTest, NullLength)
38 const char* str[] = {"foo"};
39 pp::Input input(1, str, NULL);
40 EXPECT_EQ(3u, input.length(0));
43 TEST(InputTest, NegativeLength)
45 const char* str[] = {"foo"};
47 pp::Input input(1, str, length);
48 EXPECT_EQ(3u, input.length(0));
51 TEST(InputTest, ActualLength)
53 const char* str[] = {"foobar"};
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));
61 TEST(InputTest, String)
63 const char* str[] = {"foo"};
64 pp::Input input(1, str, NULL);
65 EXPECT_STREQ(str[0], input.string(0));
68 TEST(InputTest, ReadSingleString)
71 const char* str[] = {"foo"};
72 char buf[4] = {'\0', '\0', '\0', '\0'};
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));
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));
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));
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));
105 TEST(InputTest, ReadMultipleStrings)
108 const char* str[] = {"f", "o", "o"};
109 char buf[4] = {'\0', '\0', '\0', '\0'};
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));
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));
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));
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));
142 TEST(InputTest, ReadStringsWithLength)
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'};
152 pp::Input input(count, str, length);
153 EXPECT_EQ(maxSize, input.read(buf, maxSize));
154 EXPECT_STREQ("fobar", buf);