Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -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> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include "aidl_language.h" |
| 22 | #include "type_java.h" |
| 23 | |
| 24 | using std::unique_ptr; |
| 25 | |
| 26 | namespace android { |
| 27 | namespace aidl { |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 28 | namespace java { |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 29 | |
| 30 | class JavaTypeNamespaceTest : public ::testing::Test { |
| 31 | protected: |
Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 32 | void SetUp() override { |
| 33 | types_.Init(); |
| 34 | } |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 35 | JavaTypeNamespace types_; |
| 36 | }; |
| 37 | |
| 38 | TEST_F(JavaTypeNamespaceTest, HasSomeBasicTypes) { |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 39 | EXPECT_TRUE(types_.HasTypeByCanonicalName("void")); |
| 40 | EXPECT_TRUE(types_.HasTypeByCanonicalName("int")); |
| 41 | EXPECT_TRUE(types_.HasTypeByCanonicalName("java.lang.String")); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | TEST_F(JavaTypeNamespaceTest, ContainerTypeCreation) { |
| 45 | // We start with no knowledge of parcelables or lists of them. |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 46 | EXPECT_FALSE(types_.HasTypeByCanonicalName("Foo")); |
| 47 | EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 48 | unique_ptr<AidlParcelable> parcelable(new AidlParcelable( |
Jiyong Park | a6605ab | 2018-11-11 14:30:21 +0900 | [diff] [blame] | 49 | AIDL_LOCATION_HERE, new AidlQualifiedName(AIDL_LOCATION_HERE, "Foo", ""), {"a", "goog"}, "")); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 50 | // Add the parcelable type we care about. |
Casey Dahlin | c1f39b4 | 2015-11-24 10:34:34 -0800 | [diff] [blame] | 51 | EXPECT_TRUE(types_.AddParcelableType(*parcelable.get(), __FILE__)); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 52 | // Now we can find the parcelable type, but not the List of them. |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 53 | EXPECT_TRUE(types_.HasTypeByCanonicalName("a.goog.Foo")); |
| 54 | EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 55 | // But after we add the list explicitly... |
Jiyong Park | d59a10d | 2018-07-18 11:12:55 +0900 | [diff] [blame] | 56 | std::vector<std::unique_ptr<AidlTypeSpecifier>>* type_args = |
| 57 | new std::vector<std::unique_ptr<AidlTypeSpecifier>>(); |
Steven Moreland | 02e012e | 2018-08-02 14:58:10 -0700 | [diff] [blame] | 58 | type_args->emplace_back(new AidlTypeSpecifier(AIDL_LOCATION_HERE, "Foo", false, nullptr, "")); |
| 59 | AidlTypeSpecifier container_type(AIDL_LOCATION_HERE, "List", false, type_args, ""); |
Christopher Wiley | 934a82d | 2016-01-27 13:02:24 -0800 | [diff] [blame] | 60 | EXPECT_TRUE(types_.MaybeAddContainerType(container_type)); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 61 | // This should work. |
Christopher Wiley | 9ab0623 | 2016-01-27 14:55:18 -0800 | [diff] [blame] | 62 | EXPECT_TRUE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Christopher Wiley | db154a5 | 2015-09-28 16:32:25 -0700 | [diff] [blame] | 65 | } // namespace java |
Christopher Wiley | 4582ecb | 2015-09-25 13:27:45 -0700 | [diff] [blame] | 66 | } // namespace android |
| 67 | } // namespace aidl |