blob: 39813634b1e189a503219b99ec2c2e69d530ca80 [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"
Christopher Wiley775fa1f2015-09-22 15:00:12 -070023#include "type_java.h"
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070024
25namespace android {
26namespace aidl {
Christopher Wileydb154a52015-09-28 16:32:25 -070027namespace java {
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070028namespace {
29
30const char kExpectedClassOutput[] =
31R"(// class comment
32final class TestClass extends SuperClass
33{
34}
35)";
36
37} // namespace
38
39TEST(AstJavaTests, GeneratesClass) {
Christopher Wiley8b2d3ee2015-09-23 15:43:01 -070040 JavaTypeNamespace types;
Christopher Wiley56799522015-10-31 10:17:04 -070041 types.Init();
Christopher Wiley09af4692015-10-30 11:48:25 -070042 Type class_type(&types, "TestClass", ValidatableType::KIND_GENERATED,
43 false, false);
44 Type extend_type(&types, "SuperClass", ValidatableType::KIND_BUILT_IN,
45 false, false);
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070046 Class a_class;
47 a_class.comment = "// class comment";
48 a_class.modifiers = FINAL;
49 a_class.what = Class::CLASS;
50 a_class.type = &class_type;
51 a_class.extends = &extend_type;
52
53 string actual_output;
Christopher Wiley413e0422015-09-18 10:54:51 -070054 CodeWriterPtr writer = GetStringWriter(&actual_output);
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070055 a_class.Write(writer.get());
56 EXPECT_EQ(string(kExpectedClassOutput), actual_output);
57}
58
Christopher Wileydb154a52015-09-28 16:32:25 -070059} // namespace java
Christopher Wileyfdeb0f42015-09-11 15:38:22 -070060} // namespace aidl
61} // namespace android