blob: 25392ee06a60b19565715b9f5616bec28f7b34c5 [file] [log] [blame]
Vitaly Buka4615e0d2015-10-14 15:35:12 -07001// Copyright 2015 The Weave Authors. All rights reserved.
Alex Vakulenko6201d2d2014-07-16 14:46:48 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Vitaly Buka912b6982015-07-06 11:13:03 -07005#ifndef LIBWEAVE_SRC_COMMANDS_UNITTEST_UTILS_H_
6#define LIBWEAVE_SRC_COMMANDS_UNITTEST_UTILS_H_
Alex Vakulenko6201d2d2014-07-16 14:46:48 -07007
8#include <memory>
9#include <string>
10
11#include <base/values.h>
Vitaly Buka7c82d292015-05-03 18:08:12 -070012#include <gtest/gtest.h>
Vitaly Buka0f6b2ec2015-08-20 15:35:19 -070013#include <weave/test/unittest_utils.h>
Alex Vakulenko6201d2d2014-07-16 14:46:48 -070014
Stefan Sauer2d16dfa2015-09-25 17:08:35 +020015#include "src/commands/prop_types.h"
16#include "src/commands/prop_values.h"
Anton Muhin01829452014-11-21 02:16:04 +040017
Vitaly Bukab6f015a2015-07-09 14:59:23 -070018namespace weave {
Vitaly Buka0f6b2ec2015-08-20 15:35:19 -070019namespace test {
Alex Vakulenko6201d2d2014-07-16 14:46:48 -070020
Vitaly Buka79c05e92015-07-29 12:25:37 -070021template <typename T>
22std::unique_ptr<const PropValue> make_prop_value(const base::Value& value) {
23 auto prop_type = PropType::Create(GetValueType<T>());
24 return prop_type->CreatePropValue(value, nullptr);
Anton Muhin01829452014-11-21 02:16:04 +040025}
26
Vitaly Buka79c05e92015-07-29 12:25:37 -070027inline std::unique_ptr<const PropValue> make_int_prop_value(int value) {
28 return make_prop_value<int>(base::FundamentalValue{value});
Anton Muhin01829452014-11-21 02:16:04 +040029}
30
Vitaly Buka79c05e92015-07-29 12:25:37 -070031inline std::unique_ptr<const PropValue> make_double_prop_value(double value) {
32 return make_prop_value<double>(base::FundamentalValue{value});
Anton Muhin01829452014-11-21 02:16:04 +040033}
34
Vitaly Buka79c05e92015-07-29 12:25:37 -070035inline std::unique_ptr<const PropValue> make_bool_prop_value(bool value) {
36 return make_prop_value<bool>(base::FundamentalValue{value});
Anton Muhin01829452014-11-21 02:16:04 +040037}
38
Vitaly Buka79c05e92015-07-29 12:25:37 -070039inline std::unique_ptr<const PropValue> make_string_prop_value(
Vitaly Bukaa647c852015-07-06 14:51:01 -070040 const std::string& value) {
Vitaly Buka79c05e92015-07-29 12:25:37 -070041 return make_prop_value<std::string>(base::StringValue{value});
Anton Muhin01829452014-11-21 02:16:04 +040042}
43
Vitaly Buka0f6b2ec2015-08-20 15:35:19 -070044} // namespace test
Vitaly Bukab6f015a2015-07-09 14:59:23 -070045} // namespace weave
Alex Vakulenko6201d2d2014-07-16 14:46:48 -070046
Vitaly Buka912b6982015-07-06 11:13:03 -070047#endif // LIBWEAVE_SRC_COMMANDS_UNITTEST_UTILS_H_