blob: 0101d423e7047fb7738e0ce12506a6a2cd2238b6 [file] [log] [blame]
Christopher Wileyfdeb0f42015-09-11 15:38:22 -07001/*
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
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070021#include "ast_java.h"
22#include "code_writer.h"
23
Christopher Wiley12e894a2016-01-29 11:55:07 -080024using std::string;
25
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070026namespace android {
27namespace aidl {
Christopher Wileydb154a52015-09-28 16:32:25 -070028namespace java {
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070029namespace {
30
31const char kExpectedClassOutput[] =
32R"(// class comment
33final class TestClass extends SuperClass
34{
35}
36)";
37
38} // namespace
39
40TEST(AstJavaTests, GeneratesClass) {
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070041 Class a_class;
42 a_class.comment = "// class comment";
43 a_class.modifiers = FINAL;
44 a_class.what = Class::CLASS;
Jeongik Cha2c5e7622019-07-23 14:15:48 +090045 a_class.type = "TestClass";
46 a_class.extends = "SuperClass";
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070047
48 string actual_output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +090049 a_class.Write(CodeWriter::ForString(&actual_output).get());
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070050 EXPECT_EQ(string(kExpectedClassOutput), actual_output);
51}
52
Jiyong Park176905e2018-07-04 22:29:41 +090053TEST(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
Christopher Wileydb154a52015-09-28 16:32:25 -070064} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070065} // namespace aidl
66} // namespace android