Skip to content

Commit

Permalink
Add static casts
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Nov 14, 2023
1 parent 4f51905 commit 268ead2
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions CesiumGltf/test/TestAccessorUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <catch2/catch.hpp>

#include <cstring>

using namespace CesiumGltf;

TEST_CASE("Test CountFromAccessor") {
Expand All @@ -14,7 +16,7 @@ TEST_CASE("Test CountFromAccessor") {
buffer.cesium.data.data(),
featureIds.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -24,7 +26,7 @@ TEST_CASE("Test CountFromAccessor") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::UNSIGNED_BYTE;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(uint8_t);
accessor.count = bufferView.byteLength;

SECTION("Handles invalid accessor") {
// Wrong type
Expand Down Expand Up @@ -67,7 +69,7 @@ TEST_CASE("Test GetFeatureIdAccessorView") {
buffer.cesium.data.data(),
featureIds0.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -77,7 +79,7 @@ TEST_CASE("Test GetFeatureIdAccessorView") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::UNSIGNED_BYTE;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(uint8_t);
accessor.count = bufferView.byteLength;
}

std::vector<uint16_t> featureIds1{5, 6, 7, 8};
Expand All @@ -90,7 +92,7 @@ TEST_CASE("Test GetFeatureIdAccessorView") {
buffer.cesium.data.data(),
featureIds1.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 1;
Expand All @@ -100,7 +102,8 @@ TEST_CASE("Test GetFeatureIdAccessorView") {
accessor.bufferView = 1;
accessor.componentType = Accessor::ComponentType::UNSIGNED_SHORT;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(uint16_t);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(uint16_t));
}

Mesh& mesh = model.meshes.emplace_back();
Expand Down Expand Up @@ -174,7 +177,7 @@ TEST_CASE("FeatureIdFromAccessor") {
buffer.cesium.data.data(),
featureIds.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -184,7 +187,7 @@ TEST_CASE("FeatureIdFromAccessor") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::BYTE;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(int8_t);
accessor.count = bufferView.byteLength;

SECTION("Handles invalid accessor") {
// Wrong component type
Expand Down Expand Up @@ -216,7 +219,7 @@ TEST_CASE("Test GetIndexAccessorView") {
buffer.cesium.data.data(),
indices.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -226,7 +229,7 @@ TEST_CASE("Test GetIndexAccessorView") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::UNSIGNED_BYTE;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(uint8_t);
accessor.count = bufferView.byteLength;
}

Mesh& mesh = model.meshes.emplace_back();
Expand Down Expand Up @@ -298,7 +301,7 @@ TEST_CASE("Test FaceVertexIndicesFromAccessor") {
buffer.cesium.data.data(),
indices.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -308,7 +311,8 @@ TEST_CASE("Test FaceVertexIndicesFromAccessor") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::UNSIGNED_INT;
accessor.type = Accessor::Type::SCALAR;
accessor.count = bufferView.byteLength / sizeof(uint32_t);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(uint32_t));

SECTION("Handles invalid accessor") {
// Wrong component type
Expand Down Expand Up @@ -397,7 +401,7 @@ TEST_CASE("Test GetTexCoordAccessorView") {
buffer.cesium.data.data(),
texCoords0.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -407,7 +411,8 @@ TEST_CASE("Test GetTexCoordAccessorView") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::FLOAT;
accessor.type = Accessor::Type::VEC2;
accessor.count = bufferView.byteLength / sizeof(glm::vec2);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(glm::vec2));
}

std::vector<glm::u8vec2> texCoords1{
Expand All @@ -424,7 +429,7 @@ TEST_CASE("Test GetTexCoordAccessorView") {
buffer.cesium.data.data(),
texCoords1.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 1;
Expand All @@ -435,7 +440,8 @@ TEST_CASE("Test GetTexCoordAccessorView") {
accessor.componentType = Accessor::ComponentType::UNSIGNED_BYTE;
accessor.type = Accessor::Type::VEC2;
accessor.normalized = true;
accessor.count = bufferView.byteLength / sizeof(glm::u8vec2);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(glm::u8vec2));
}

Mesh& mesh = model.meshes.emplace_back();
Expand Down Expand Up @@ -528,7 +534,7 @@ TEST_CASE("Test TexCoordFromAccessor") {
buffer.cesium.data.data(),
texCoords0.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 0;
Expand All @@ -538,7 +544,8 @@ TEST_CASE("Test TexCoordFromAccessor") {
accessor.bufferView = 0;
accessor.componentType = Accessor::ComponentType::FLOAT;
accessor.type = Accessor::Type::VEC2;
accessor.count = bufferView.byteLength / sizeof(glm::vec2);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(glm::vec2));
}

std::vector<glm::u8vec2> texCoords1{
Expand All @@ -555,7 +562,7 @@ TEST_CASE("Test TexCoordFromAccessor") {
buffer.cesium.data.data(),
texCoords1.data(),
buffer.cesium.data.size());
buffer.byteLength = buffer.cesium.data.size();
buffer.byteLength = static_cast<int64_t>(buffer.cesium.data.size());

BufferView& bufferView = model.bufferViews.emplace_back();
bufferView.buffer = 1;
Expand All @@ -566,7 +573,8 @@ TEST_CASE("Test TexCoordFromAccessor") {
accessor.componentType = Accessor::ComponentType::UNSIGNED_BYTE;
accessor.type = Accessor::Type::VEC2;
accessor.normalized = true;
accessor.count = bufferView.byteLength / sizeof(glm::u8vec2);
accessor.count =
bufferView.byteLength / static_cast<int64_t>(sizeof(glm::u8vec2));
}

Mesh& mesh = model.meshes.emplace_back();
Expand Down

0 comments on commit 268ead2

Please sign in to comment.