Home | History | Annotate | Download | only in update_manager
      1 //
      2 // Copyright (C) 2014 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 UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
     18 #define UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
     19 
     20 #include <iostream>  // NOLINT(readability/streams)
     21 #include <memory>
     22 
     23 #include <base/time/time.h>
     24 #include <gtest/gtest.h>
     25 
     26 #include "update_engine/update_manager/policy.h"
     27 #include "update_engine/update_manager/variable.h"
     28 
     29 namespace chromeos_update_manager {
     30 
     31 // A help class with common functionality for use in Update Manager testing.
     32 class UmTestUtils {
     33  public:
     34   // A default timeout to use when making various queries.
     35   static const base::TimeDelta DefaultTimeout() {
     36     return base::TimeDelta::FromSeconds(kDefaultTimeoutInSeconds);
     37   }
     38 
     39   // Calls GetValue on |variable| and expects its result to be |expected|.
     40   template<typename T>
     41   static void ExpectVariableHasValue(const T& expected, Variable<T>* variable) {
     42     ASSERT_NE(nullptr, variable);
     43     std::unique_ptr<const T> value(
     44         variable->GetValue(DefaultTimeout(), nullptr));
     45     ASSERT_NE(nullptr, value.get()) << "Variable: " << variable->GetName();
     46     EXPECT_EQ(expected, *value) << "Variable: " << variable->GetName();
     47   }
     48 
     49   // Calls GetValue on |variable| and expects its result to be null.
     50   template<typename T>
     51   static void ExpectVariableNotSet(Variable<T>* variable) {
     52     ASSERT_NE(nullptr, variable);
     53     std::unique_ptr<const T> value(
     54         variable->GetValue(DefaultTimeout(), nullptr));
     55     EXPECT_EQ(nullptr, value.get()) << "Variable: " << variable->GetName();
     56   }
     57 
     58  private:
     59   static const unsigned kDefaultTimeoutInSeconds;
     60 };
     61 
     62 // PrintTo() functions are used by gtest to print these values. They need to be
     63 // defined on the same namespace where the type was defined.
     64 void PrintTo(const EvalStatus& status, ::std::ostream* os);
     65 
     66 }  // namespace chromeos_update_manager
     67 
     68 #endif  // UPDATE_ENGINE_UPDATE_MANAGER_UMTEST_UTILS_H_
     69