1 /*
2  * Copyright (C) 2015, 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 <gtest/gtest.h>
20 
21 #include "ast_java.h"
22 #include "code_writer.h"
23 
24 using std::string;
25 
26 namespace android {
27 namespace aidl {
28 namespace java {
29 namespace {
30 
31 const char kExpectedClassOutput[] =
32 R"(// class comment
33 final class TestClass extends SuperClass
34 {
35 }
36 )";
37 
38 }  // namespace
39 
TEST(AstJavaTests,GeneratesClass)40 TEST(AstJavaTests, GeneratesClass) {
41   Class a_class;
42   a_class.comment = "// class comment";
43   a_class.modifiers = FINAL;
44   a_class.what = Class::CLASS;
45   a_class.type = "TestClass";
46   a_class.extends = "SuperClass";
47 
48   string actual_output;
49   a_class.Write(CodeWriter::ForString(&actual_output).get());
50   EXPECT_EQ(string(kExpectedClassOutput), actual_output);
51 }
52 
TEST(AstJavaTests,ToString)53 TEST(AstJavaTests, ToString) {
54   std::string literal = "public void foo() {}";
55   LiteralClassElement ce(literal);
56   std::string actual = ce.ToString();
57   EXPECT_EQ(literal, actual);
58 
59   std::string written;
60   ce.Write(CodeWriter::ForString(&written).get());
61   EXPECT_EQ(literal, written);
62 }
63 
64 }  // namespace java
65 }  // namespace aidl
66 }  // namespace android
67