92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
/*
|
|
* Copyright 2015-2020 Michele "King_DuckZ" Santullo
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "vectorwrapper/vectorwrapper.hpp"
|
|
#include <gtest/gtest.h>
|
|
#include <cstddef>
|
|
|
|
namespace vwr {
|
|
template <> struct VectorWrapperInfo<unsigned short int[3]> {
|
|
enum { dimensions = 3 };
|
|
using scalar_type = unsigned short int;
|
|
using vector_type = unsigned short int[3];
|
|
using higer_vector_type = unsigned short int[4];
|
|
enum {
|
|
offset_x = sizeof(scalar_type) * 0,
|
|
offset_y = sizeof(scalar_type) * 1,
|
|
offset_z = sizeof(scalar_type) * 2
|
|
};
|
|
};
|
|
|
|
template <> struct VectorWrapperInfo<unsigned short int[4]> {
|
|
enum { dimensions = 4 };
|
|
using scalar_type = unsigned short int;
|
|
using vector_type = unsigned short int[4];
|
|
using lower_vector_type = unsigned short int[3];
|
|
enum {
|
|
offset_x = sizeof(scalar_type) * 0,
|
|
offset_y = sizeof(scalar_type) * 1,
|
|
offset_z = sizeof(scalar_type) * 2,
|
|
offset_w = sizeof(scalar_type) * 3
|
|
};
|
|
};
|
|
} //namespace vwr
|
|
|
|
namespace {
|
|
typedef vwr::Vec<unsigned short int[3]> vec3;
|
|
typedef vwr::Vec<unsigned short int[4]> vec4;
|
|
} //unnamed namespace
|
|
|
|
TEST(vwr, c_array) {
|
|
constexpr const unsigned short int test_val = 0b1010101010101010;
|
|
vec4 myvec4(test_val);
|
|
vec3 myvec3(myvec4.xyz());
|
|
|
|
EXPECT_EQ(myvec3, myvec4.xyz());
|
|
EXPECT_EQ(test_val, myvec3.x());
|
|
EXPECT_EQ(test_val, myvec3.y());
|
|
EXPECT_EQ(test_val, myvec3.z());
|
|
|
|
for (int z = 0; z < 4; ++z) {
|
|
const auto val = myvec4.data()[z];
|
|
EXPECT_EQ(test_val, val);
|
|
}
|
|
|
|
myvec4.data()[1] = 5;
|
|
{
|
|
unsigned short int vals[4] { test_val, 5, test_val, test_val };
|
|
for (int z = 0; z < 4; ++z) {
|
|
const auto val = myvec4.data()[z];
|
|
EXPECT_EQ(vals[z], val);
|
|
}
|
|
}
|
|
|
|
myvec4.w() = 0xFFFFU;
|
|
{
|
|
unsigned short int vals[4] { test_val, 5, test_val, 0xFFFFU };
|
|
for (int z = 0; z < 4; ++z) {
|
|
const auto val = myvec4.data()[z];
|
|
EXPECT_EQ(vals[z], val);
|
|
}
|
|
}
|
|
|
|
myvec3.x() = 1001U;
|
|
myvec3.y() = 1503U;
|
|
myvec3.z() = 2007U;
|
|
EXPECT_EQ(4511U, myvec3.x() + myvec3.y() + myvec3.z());
|
|
|
|
EXPECT_NE(myvec3, myvec4.xyz());
|
|
}
|