blob: daa10994d8e1428dd6868843831c0f4307c5e286 [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <utility>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "cc_bindings_from_rs/test/structs/structs_cc_api.h"
namespace crubit {
namespace {
TEST(StructsTest, ReprCPointReturnedOrTakenByValue) {
structs::repr_c::Point p = structs::repr_c::create(123, 456);
EXPECT_EQ(123, structs::repr_c::get_x(std::move(p)));
}
TEST(StructsTest, DefaultReprPointReturnedOrTakenByValue) {
structs::default_repr::Point p = structs::default_repr::create(123, 456);
EXPECT_EQ(123, structs::default_repr::get_x(std::move(p)));
}
TEST(StructsTest, StructInteger) {
namespace test = structs::abi_classification;
test::StructInteger x = test::StructInteger::create(123);
test::StructInteger y = test::StructInteger::create(456);
test::StructInteger product =
test::StructInteger::multiply(std::move(x), std::move(y));
EXPECT_EQ(123 * 456, test::StructInteger::inspect(std::move(product)));
}
TEST(StructsTest, StructFloat) {
namespace test = structs::abi_classification;
test::StructFloat x = test::StructFloat::create(456.0);
test::StructFloat y = test::StructFloat::create(789.0);
test::StructFloat product =
test::StructFloat::multiply(std::move(x), std::move(y));
EXPECT_EQ(456.0 * 789.0, test::StructFloat::inspect(std::move(product)));
}
TEST(StructsTest, StructMemory) {
namespace test = structs::abi_classification;
test::StructMemory x = test::StructMemory::create(321);
test::StructMemory y = test::StructMemory::create(654);
test::StructMemory product =
test::StructMemory::multiply(std::move(x), std::move(y));
EXPECT_EQ(321 * 654, test::StructMemory::inspect(std::move(product)));
}
} // namespace
} // namespace crubit