• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <string>
18 
19 #include <android-base/test_utils.h>
20 #include <gtest/gtest.h>
21 
22 #include "CodeWriter.h"
23 
24 namespace {
25 
26 constexpr const char* kIndent = "    ";
27 
28 constexpr const char* kHelloWorld =
29     R"(#include <stdio.h>
30 
31 int main() {
32     printf("Hello World\n");
33 }
34 )";
35 
36 }  // namespace
37 
TEST(SyspropTest,CodeWriterIndentOutputTest)38 TEST(SyspropTest, CodeWriterIndentOutputTest) {
39   CodeWriter writer(kIndent);
40   writer.Write("test1\ntest2\n");
41   writer.Indent();
42   writer.Write("test3\ntest4\n");
43   writer.Indent();
44   writer.Write("test5\ntest6\n");
45   writer.Dedent();
46   writer.Dedent();
47   writer.Write("test7\ntest8\n");
48 
49   ASSERT_EQ(writer.Code(),
50             "test1\n"
51             "test2\n"
52             "    test3\n"
53             "    test4\n"
54             "        test5\n"
55             "        test6\n"
56             "test7\n"
57             "test8\n");
58 }
59 
TEST(SyspropTest,CodeWriterCodeGenerationTest)60 TEST(SyspropTest, CodeWriterCodeGenerationTest) {
61   CodeWriter writer(kIndent);
62   writer.Write(kHelloWorld);
63   ASSERT_EQ(writer.Code(), kHelloWorld);
64 }
65