// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* DO NOT EDIT. Generated from {{module.path}} */
{%- if variant -%}
{%- set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%- set variant_path = module.path -%}
{%- endif %}
#include "{{variant_path}}_c.h"
#include <math.h>
#include "testing/gtest/include/gtest/gtest.h"
{% set test_class_name = namespaces_as_array|first|title %}
class {{test_class_name}}StructTest : public ::testing::Test {
public:
{{test_class_name}}StructTest(const {{test_class_name}}StructTest&) = delete;
{{test_class_name}}StructTest& operator=(const {{test_class_name}}StructTest&) = delete;
protected:
void SetUp() override {
}
void TearDown() override {
}
{{test_class_name}}StructTest() {}
~{{test_class_name}}StructTest() override {}
};
{%- for struct in structs %}
{%- set struct_name = struct|get_name_for_kind %}
// Test Struct {{struct_name}} setters and getters.
TEST_F({{test_class_name}}StructTest, Test{{struct_name}}) {
{{struct_name}}Ptr first = {{struct_name}}_Create();
{{struct_name}}Ptr second = {{struct_name}}_Create();
// Copy values from |first| to |second|.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %}
// TODO(mef): Test array |{{packed_field.field.name}}|.
{%- elif kind|is_struct_kind %}
{{kind|cpp_wrapper_type}}Ptr test_{{packed_field.field.name}} = {{kind|cpp_wrapper_type}}_Create();
EXPECT_EQ({{struct_name}}_{{packed_field.field.name}}_get(first), nullptr);
{{struct_name}}_{{packed_field.field.name}}_set(first, test_{{packed_field.field.name}});
EXPECT_NE({{struct_name}}_{{packed_field.field.name}}_get(first), nullptr);
{{struct_name}}_{{packed_field.field.name}}_set(first, nullptr);
EXPECT_EQ({{struct_name}}_{{packed_field.field.name}}_get(first), nullptr);
{{struct_name}}_{{packed_field.field.name}}_move(first, test_{{packed_field.field.name}});
EXPECT_NE({{struct_name}}_{{packed_field.field.name}}_get(first), nullptr);
{{struct_name}}_{{packed_field.field.name}}_move(first, nullptr);
EXPECT_EQ({{struct_name}}_{{packed_field.field.name}}_get(first), nullptr);
{{kind|cpp_wrapper_type}}_Destroy(test_{{packed_field.field.name}});
{%- else %}
{{struct_name}}_{{packed_field.field.name}}_set(second,
{{struct_name}}_{{packed_field.field.name}}_get(first));
{%- if kind|cpp_wrapper_type == 'double' %}
EXPECT_TRUE(
{{struct_name}}_{{packed_field.field.name}}_get(first) ==
{{struct_name}}_{{packed_field.field.name}}_get(second) ||
isnan({{struct_name}}_{{packed_field.field.name}}_get(first)) &&
isnan({{struct_name}}_{{packed_field.field.name}}_get(second)));
{%- else %}
{%- if kind|is_string_kind %}
EXPECT_STREQ(
{%- else %}
EXPECT_EQ(
{%- endif %}
{{struct_name}}_{{packed_field.field.name}}_get(first),
{{struct_name}}_{{packed_field.field.name}}_get(second));
{%- endif %}
{%- endif %}
{%- endfor %}
{{struct_name}}_Destroy(first);
{{struct_name}}_Destroy(second);
}
{%- endfor %}