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>")); |
Christopher Wiley | d76067c | 2015-10-19 17:00:13 -0700 | [diff] [blame] | 48 | unique_ptr<AidlParcelable> parcelable( |
Christopher Wiley | 8aa4d9f | 2015-11-16 19:10:45 -0800 | [diff] [blame] | 49 | new AidlParcelable(new AidlQualifiedName("Foo", ""), 0, {"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>>(); |
| 58 | type_args->emplace_back(new AidlTypeSpecifier("Foo", 0, "", false)); |
| 59 | AidlTypeSpecifier container_type("List", 0, "", false /* not array */, 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 |