Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -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 <memory> |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 18 | #include <string> |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | |
| 22 | #include "type_cpp.h" |
| 23 | |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 24 | using std::string; |
| 25 | using std::unique_ptr; |
| 26 | |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace aidl { |
| 29 | namespace cpp { |
| 30 | |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 31 | namespace { |
| 32 | |
| 33 | string kParcelableDotName = "Outer.Inner"; |
| 34 | string kParcelableColonName = "Outer::Inner"; |
| 35 | |
| 36 | } // namespace |
| 37 | |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 38 | class CppTypeNamespaceTest : public ::testing::Test { |
| 39 | protected: |
Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 40 | void SetUp() override { |
| 41 | types_.Init(); |
| 42 | } |
Christopher Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 43 | TypeNamespace types_; |
| 44 | }; |
| 45 | |
| 46 | TEST_F(CppTypeNamespaceTest, HasSomeBasicTypes) { |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 47 | 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 Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 57 | TEST_F(CppTypeNamespaceTest, SupportsListString) { |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 58 | EXPECT_TRUE( |
| 59 | types_.HasTypeByCanonicalName("java.util.List<java.lang.String>")); |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Ningyuan Wang | d17c58b | 2016-09-29 14:33:14 -0700 | [diff] [blame] | 62 | TEST_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 Wiley | a8a2dc0 | 2015-09-28 16:35:31 -0700 | [diff] [blame] | 70 | } // namespace cpp |
| 71 | } // namespace android |
| 72 | } // namespace aidl |