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 "java/AnnotationProcessor.h" 18 19 #include "test/Test.h" 20 21 using ::testing::Eq; 22 using ::testing::HasSubstr; 23 using ::testing::Not; 24 25 namespace aapt { 26 27 TEST(AnnotationProcessorTest, EmitsDeprecated) { 28 const char* comment = 29 "Some comment, and it should contain a marker word, " 30 "something that marks this resource as nor needed. " 31 "{@deprecated That's the marker! }"; 32 33 AnnotationProcessor processor; 34 processor.AppendComment(comment); 35 36 std::stringstream result; 37 processor.WriteToStream(&result, ""); 38 std::string annotations = result.str(); 39 40 EXPECT_THAT(annotations, HasSubstr("@Deprecated")); 41 } 42 43 TEST(AnnotationProcessorTest, EmitsSystemApiAnnotationAndRemovesFromComment) { 44 AnnotationProcessor processor; 45 processor.AppendComment("@SystemApi This is a system API"); 46 47 std::stringstream result; 48 processor.WriteToStream(&result, ""); 49 std::string annotations = result.str(); 50 51 EXPECT_THAT(annotations, HasSubstr("@android.annotation.SystemApi")); 52 EXPECT_THAT(annotations, Not(HasSubstr("@SystemApi"))); 53 EXPECT_THAT(annotations, HasSubstr("This is a system API")); 54 } 55 56 TEST(AnnotationProcessor, ExtractsFirstSentence) { 57 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence("This is the only sentence"), 58 Eq("This is the only sentence")); 59 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence( 60 "This is the\n first sentence. This is the rest of the paragraph."), 61 Eq("This is the\n first sentence.")); 62 EXPECT_THAT(AnnotationProcessor::ExtractFirstSentence( 63 "This is the first sentence with a {@link android.R.styleable.Theme}."), 64 Eq("This is the first sentence with a {@link android.R.styleable.Theme}.")); 65 } 66 67 } // namespace aapt 68