| 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" |
| Christopher Wiley | 775fa1f | 2015-09-22 15:00:12 -0700 | [diff] [blame] | 23 | #include "type_java.h" |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 24 | |
| Christopher Wiley | 12e894a | 2016-01-29 11:55:07 -0800 | [diff] [blame] | 25 | using std::string; |
| 26 | |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace aidl { |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 29 | namespace java { |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | const char kExpectedClassOutput[] = |
| 33 | R"(// class comment |
| 34 | final class TestClass extends SuperClass |
| 35 | { |
| 36 | } |
| 37 | )"; |
| 38 | |
| 39 | } // namespace |
| 40 | |
| 41 | TEST(AstJavaTests, GeneratesClass) { |
| Christopher Wiley | 8b2d3ee | 2015-09-23 15:43:01 -0700 | [diff] [blame] | 42 | JavaTypeNamespace types; |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 43 | types.Init(); |
| Christopher Wiley | 09af469 | 2015-10-30 11:48:25 -0700 | [diff] [blame] | 44 | Type class_type(&types, "TestClass", ValidatableType::KIND_GENERATED, |
| 45 | false, false); |
| 46 | Type extend_type(&types, "SuperClass", ValidatableType::KIND_BUILT_IN, |
| 47 | false, false); |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 48 | Class a_class; |
| 49 | a_class.comment = "// class comment"; |
| 50 | a_class.modifiers = FINAL; |
| 51 | a_class.what = Class::CLASS; |
| 52 | a_class.type = &class_type; |
| 53 | a_class.extends = &extend_type; |
| 54 | |
| 55 | string actual_output; |
| Christopher Wiley | 413e042 | 2015-09-18 10:54:51 -0700 | [diff] [blame] | 56 | CodeWriterPtr writer = GetStringWriter(&actual_output); |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 57 | a_class.Write(writer.get()); |
| 58 | EXPECT_EQ(string(kExpectedClassOutput), actual_output); |
| 59 | } |
| 60 | |
| Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 61 | } // namespace java |
| Christopher Wiley | fdeb0f4 | 2015-09-11 15:38:22 -0700 | [diff] [blame] | 62 | } // namespace aidl |
| 63 | } // namespace android |