1 /* 2 * Copyright (C) 2018 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 #ifndef LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_TESTING_BASE_PARSER_TEST_H_ 18 #define LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_TESTING_BASE_PARSER_TEST_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "annotator/datetime/parser.h" 24 #include "annotator/datetime/testing/base-parser-test.h" 25 #include "annotator/types.h" 26 #include "gmock/gmock.h" 27 #include "gtest/gtest.h" 28 29 namespace libtextclassifier3 { 30 31 class DateTimeParserTest : public testing::Test { 32 public: 33 bool HasNoResult(const std::string& text, bool anchor_start_end = false, 34 const std::string& timezone = "Europe/Zurich", 35 AnnotationUsecase annotation_usecase = 36 AnnotationUsecase_ANNOTATION_USECASE_SMART); 37 38 bool ParsesCorrectly( 39 const std::string& marked_text, 40 const std::vector<int64>& expected_ms_utcs, 41 DatetimeGranularity expected_granularity, 42 std::vector<std::vector<DatetimeComponent>> datetime_components, 43 bool anchor_start_end = false, 44 const std::string& timezone = "Europe/Zurich", 45 const std::string& locales = "en-US", 46 AnnotationUsecase annotation_usecase = 47 AnnotationUsecase_ANNOTATION_USECASE_SMART); 48 49 bool ParsesCorrectly( 50 const std::string& marked_text, const int64 expected_ms_utc, 51 DatetimeGranularity expected_granularity, 52 std::vector<std::vector<DatetimeComponent>> datetime_components, 53 bool anchor_start_end = false, 54 const std::string& timezone = "Europe/Zurich", 55 const std::string& locales = "en-US", 56 AnnotationUsecase annotation_usecase = 57 AnnotationUsecase_ANNOTATION_USECASE_SMART); 58 59 bool ParsesCorrectlyGerman( 60 const std::string& marked_text, 61 const std::vector<int64>& expected_ms_utcs, 62 DatetimeGranularity expected_granularity, 63 std::vector<std::vector<DatetimeComponent>> datetime_components); 64 65 bool ParsesCorrectlyGerman( 66 const std::string& marked_text, const int64 expected_ms_utc, 67 DatetimeGranularity expected_granularity, 68 std::vector<std::vector<DatetimeComponent>> datetime_components); 69 70 bool ParsesCorrectlyChinese( 71 const std::string& marked_text, const int64 expected_ms_utc, 72 DatetimeGranularity expected_granularity, 73 std::vector<std::vector<DatetimeComponent>> datetime_components); 74 75 // Exposes the date time parser for tests and evaluations. 76 virtual const DatetimeParser* DatetimeParserForTests() const = 0; 77 }; 78 79 } // namespace libtextclassifier3 80 81 #endif // LIBTEXTCLASSIFIER_ANNOTATOR_DATETIME_TESTING_BASE_PARSER_TEST_H_ 82