blob: 46b5db84a9edd58e61992e880521f50515117f9d [file] [log] [blame]
Christopher Wileya8a2dc02015-09-28 16:35:31 -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 <memory>
Ningyuan Wangd17c58b2016-09-29 14:33:14 -070018#include <string>
Christopher Wileya8a2dc02015-09-28 16:35:31 -070019
20#include <gtest/gtest.h>
21
22#include "type_cpp.h"
23
Ningyuan Wangd17c58b2016-09-29 14:33:14 -070024using std::string;
25using std::unique_ptr;
26
Christopher Wileya8a2dc02015-09-28 16:35:31 -070027namespace android {
28namespace aidl {
29namespace cpp {
30
Ningyuan Wangd17c58b2016-09-29 14:33:14 -070031namespace {
32
33string kParcelableDotName = "Outer.Inner";
34string kParcelableColonName = "Outer::Inner";
35
36} // namespace
37
Christopher Wileya8a2dc02015-09-28 16:35:31 -070038class CppTypeNamespaceTest : public ::testing::Test {
39 protected:
Christopher Wiley56799522015-10-31 10:17:04 -070040 void SetUp() override {
41 types_.Init();
42 }
Christopher Wileya8a2dc02015-09-28 16:35:31 -070043 TypeNamespace types_;
44};
45
46TEST_F(CppTypeNamespaceTest, HasSomeBasicTypes) {
Christopher Wiley9ab06232016-01-27 14:55:18 -080047 EXPECT_TRUE(types_.HasTypeByCanonicalName("byte"));
48 EXPECT_TRUE(types_.HasTypeByCanonicalName("int"));
49 EXPECT_TRUE(types_.HasTypeByCanonicalName("long"));
50 EXPECT_TRUE(types_.HasTypeByCanonicalName("float"));
51 EXPECT_TRUE(types_.HasTypeByCanonicalName("double"));
52 EXPECT_TRUE(types_.HasTypeByCanonicalName("boolean"));
53 EXPECT_TRUE(types_.HasTypeByCanonicalName("char"));
54 EXPECT_TRUE(types_.HasTypeByCanonicalName("String"));
Christopher Wileya8a2dc02015-09-28 16:35:31 -070055}
56
Christopher Wiley56c9bf32015-10-30 10:41:12 -070057TEST_F(CppTypeNamespaceTest, SupportsListString) {
Christopher Wiley9ab06232016-01-27 14:55:18 -080058 EXPECT_TRUE(
59 types_.HasTypeByCanonicalName("java.util.List<java.lang.String>"));
Christopher Wiley56c9bf32015-10-30 10:41:12 -070060}
61
Ningyuan Wangd17c58b2016-09-29 14:33:14 -070062TEST_F(CppTypeNamespaceTest, SupportsNestedParcelableClass) {
63 unique_ptr<AidlParcelable> parcelable(
64 new AidlParcelable(new AidlQualifiedName(kParcelableDotName, ""),
65 0,
66 {"a", "goog"}));
67 EXPECT_EQ(parcelable->GetCppName(), kParcelableColonName);
68}
69
Christopher Wileya8a2dc02015-09-28 16:35:31 -070070} // namespace cpp
71} // namespace android
72} // namespace aidl