chromium/tools/json_schema_compiler/test/error_generation_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "tools/json_schema_compiler/test/error_generation.h"

#include <memory>
#include <vector>

#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/test_util.h"

namespace errors = test::api::error_generation;
Value;
Dictionary;
List;

template <typename T, typename Value>
std::u16string GetPopulateError(const Value& value) {}

testing::AssertionResult EqualsUtf16(const std::string& expected,
                                     const std::u16string& actual) {}

// GenerateTypePopulate errors

TEST() {
  {
    base::Value value = Dictionary("string", Value("bling"));
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value(Value::Type::LIST);
    EXPECT_TRUE();
  }
  {
    base::Value value(Value::Type::BINARY);
    EXPECT_TRUE();
  }
}

// GenerateTypePopulateProperty errors

TEST() {
  {
    base::Value value = Dictionary("integers", Value(5));
    EXPECT_TRUE();
  }
  {
    base::Value::Dict value;
    EXPECT_TRUE();
  }
}

// GenerateParamsCheck errors

TEST() {
  {
    base::Value::List params_value;
    params_value.Append(5);
    EXPECT_TRUE();
  }
  {
    base::Value::List params_value;
    params_value.Append(5);
    params_value.Append(5);
    EXPECT_TRUE();
  }
}

// GenerateFunctionParamsCreate errors

TEST() {
  {
    base::Value::List params_value;
    params_value.Append(5);
    EXPECT_TRUE();
  }
  {
    base::Value::List params_value;
    params_value.Append(base::Value());
    EXPECT_TRUE();
  }
}

// GeneratePopulateVariableFromValue errors

TEST() {
  {
    base::Value value = Dictionary("string", Value("yes"));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("string", Value(1.1));
    EXPECT_TRUE();
  }
}

TEST() {
  {
    std::u16string error;
    base::Value::List params_value;
    params_value.Append("Yeah!");
    EXPECT_TRUE();
  }
  {
    base::Value::List params_value;
    params_value.Append(5);
    std::u16string error;
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value::Dict value;
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("otherType", Value(1.1));
    auto out = errors::ObjectType::FromValue(value.GetDict());
    ASSERT_FALSE();
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value params_value = List(Value(5));
    EXPECT_TRUE();
  }
  {
    base::Value params_value = List(Value(5), Value(false));
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value = Dictionary("data", Value(Value::Type::BINARY));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("data", Value(1.1));
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value =
        Dictionary("TheArray", base::Value(base::Value::Type::LIST));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("TheArray", Value(5));
    EXPECT_TRUE();
  }
}

// GenerateStringToEnumConversion errors

TEST() {
  {
    base::Value value = Dictionary("enumeration", Value("one"));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("enumeration", Value("bad sauce"));
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value = Dictionary("string", Value("bling"));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("string", Value(1));

    auto out = errors::OptionalTestType::FromValue(value.GetDict());
    ASSERT_FALSE();
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value = Dictionary("data", Value(Value::Type::BINARY));
    EXPECT_TRUE();
  }
  {
    // There's a bug with silent failures if the key doesn't exist.
    base::Value value = Dictionary("data", Value(1));

    auto out = errors::OptionalBinaryData::FromValue(value.GetDict());
    ASSERT_FALSE();
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value =
        Dictionary("TheArray", base::Value(base::Value::Type::LIST));
    EXPECT_TRUE();
  }
  {
    base::Value value = Dictionary("TheArray", Value(5));
    auto out = errors::ArrayObject::FromValue(value.GetDict());
    EXPECT_FALSE();
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value params_value = List(Value(5));
    EXPECT_TRUE();
  }
  {
    base::Value params_value = List(Value(5), Value(false));
    auto out = errors::OptionalChoiceType::Integers::FromValue(params_value);
    EXPECT_FALSE();
    EXPECT_TRUE();
  }
}

TEST() {
  {
    base::Value value = Dictionary("string", Value("yes"));
    EXPECT_TRUE();
  }
  {
    // We simply ignore extra keys.
    base::Value value =
        Dictionary("string", Value("yes"), "ohno", Value("many values"));
    EXPECT_TRUE();
  }
}