1 /* 2 * Copyright (C) 2023 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 #pragma once 18 19 #include <string> 20 21 #include <gmock/gmock.h> 22 #include <jsonpb/json_schema_test.h> 23 24 #include "thermal_info_config.pb.h" 25 26 namespace devices { 27 namespace shusky { 28 29 // JSON schema test wrapper. 30 class ThermalInfoConfigTest : public android::jsonpb::JsonSchemaTest { 31 public: SetUp()32 void SetUp() override { 33 JsonSchemaTest::SetUp(); 34 thermalInfoConfig_ = static_cast<ThermalConfig *>(message()); 35 } 36 ThermalConfig *thermalInfoConfig_ = nullptr; 37 }; 38 39 // Individual test checking for sensor name and type as required fields. TEST_P(ThermalInfoConfigTest,ThermalConfigRequiredFields)40TEST_P(ThermalInfoConfigTest, ThermalConfigRequiredFields) { 41 std::string error; 42 43 // Checks that no unknown fields are introduced. 44 EXPECT_TRUE(android::jsonpb::AllFieldsAreKnown(*object_, json_, &error)) 45 << "File: " << file_path_ << ": " << error; 46 47 // Check all Sensors have a Name and Type. 48 for (int i = 0; i < thermalInfoConfig_->sensors_size(); ++i) { 49 auto &&sensor = thermalInfoConfig_->sensors(i); 50 EXPECT_FALSE(sensor.name().empty()) 51 << "No name for sensor #" << i << " in " << file_path_; 52 EXPECT_FALSE(sensor.type().empty()) 53 << "No type for sensor " << sensor.name() << " in " << file_path_; 54 } 55 }; 56 57 } // namespace shusky 58 } // namespace devices