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 { 28 namespace java { 29 30 class JavaTypeNamespaceTest : public ::testing::Test { 31 protected: 32 void SetUp() override { 33 types_.Init(); 34 } 35 JavaTypeNamespace types_; 36 }; 37 38 TEST_F(JavaTypeNamespaceTest, HasSomeBasicTypes) { 39 EXPECT_TRUE(types_.HasTypeByCanonicalName("void")); 40 EXPECT_TRUE(types_.HasTypeByCanonicalName("int")); 41 EXPECT_TRUE(types_.HasTypeByCanonicalName("java.lang.String")); 42 } 43 44 TEST_F(JavaTypeNamespaceTest, ContainerTypeCreation) { 45 // We start with no knowledge of parcelables or lists of them. 46 EXPECT_FALSE(types_.HasTypeByCanonicalName("Foo")); 47 EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); 48 unique_ptr<AidlParcelable> parcelable( 49 new AidlParcelable(new AidlQualifiedName("Foo", ""), 0, {"a", "goog"})); 50 // Add the parcelable type we care about. 51 EXPECT_TRUE(types_.AddParcelableType(*parcelable.get(), __FILE__)); 52 // Now we can find the parcelable type, but not the List of them. 53 EXPECT_TRUE(types_.HasTypeByCanonicalName("a.goog.Foo")); 54 EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); 55 // But after we add the list explicitly... 56 AidlType container_type("List<Foo>", 0, "", false /* not array */); 57 EXPECT_TRUE(types_.MaybeAddContainerType(container_type)); 58 // This should work. 59 EXPECT_TRUE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>")); 60 } 61 62 } // namespace java 63 } // namespace android 64 } // namespace aidl 65