blob: a082da5e4920286e2cd22558760b0ff6b87a3288 [file] [log] [blame]
Christopher Wileyf600a552015-09-12 14:07:44 -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
21#include "ast_cpp.h"
22#include "code_writer.h"
23
24using std::string;
25
26namespace android {
27namespace aidl {
28namespace {
29
30const char kExpectedHeaderOutput[] =
31R"(#ifndef HEADER_INCLUDE_GUARD_H_
32#define HEADER_INCLUDE_GUARD_H_
33
34#include <string>
35#include <memory>
36
37namespace android {
Casey Dahlin34b86102015-09-16 16:03:06 -070038
Christopher Wileyf600a552015-09-12 14:07:44 -070039namespace test {
40
Casey Dahlin34b86102015-09-16 16:03:06 -070041
Christopher Wileyf600a552015-09-12 14:07:44 -070042} // namespace test
Casey Dahlin34b86102015-09-16 16:03:06 -070043
Christopher Wileyf600a552015-09-12 14:07:44 -070044} // namespace android
45
46#endif // HEADER_INCLUDE_GUARD_H_)";
47
48} // namespace
49
50TEST(AstCppTests, GeneratesHeader) {
Casey Dahlin34b86102015-09-16 16:03:06 -070051 CppHeader cpp_header{"HEADER_INCLUDE_GUARD_H_",
52 {"string", "memory"},
53 new CppNamespace {"android", {
54 new CppNamespace {"test", {
55 }}
56 }}
57 };
Christopher Wileyf600a552015-09-12 14:07:44 -070058 string actual_output;
59 CodeWriterPtr writer = get_string_writer(&actual_output);
60 cpp_header.Write(writer.get());
61 EXPECT_EQ(string(kExpectedHeaderOutput), actual_output);
62}
63
64} // namespace aidl
65} // namespace android