Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 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 | |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 21 | #include "ast_java.h" |
| 22 | #include "code_writer.h" |
| 23 | |
Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 24 | using std::string; |
| 25 | |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace aidl { |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 28 | namespace java { |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | const char kExpectedClassOutput[] = |
| 32 | R"(// class comment |
| 33 | final class TestClass extends SuperClass |
| 34 | { |
| 35 | } |
| 36 | )"; |
| 37 | |
| 38 | } // namespace |
| 39 | |
| 40 | TEST(AstJavaTests, GeneratesClass) { |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 41 | Class a_class; |
| 42 | a_class.comment = "// class comment"; |
| 43 | a_class.modifiers = FINAL; |
| 44 | a_class.what = Class::CLASS; |
Jeongik Cha | 2c5e762 | 2019-07-23 14:15:48 +0900 | [diff] [blame] | 45 | a_class.type = "TestClass"; |
| 46 | a_class.extends = "SuperClass"; |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 47 | |
| 48 | string actual_output; |
Jiyong Park | b78e15b | 2018-07-04 20:31:03 +0900 | [diff] [blame] | 49 | a_class.Write(CodeWriter::ForString(&actual_output).get()); |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 50 | EXPECT_EQ(string(kExpectedClassOutput), actual_output); |
| 51 | } |
| 52 | |
Jiyong Park | 176905e | 2018-07-04 22:29:41 +0900 | [diff] [blame] | 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 | |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 64 | } // namespace java |
Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 65 | } // namespace aidl |
| 66 | } // namespace android |