Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/nanoarrow/common/utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,36 +267,33 @@ TEST(DecimalTest, Decimal32Test) {

#if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18
auto dec_pos = *Decimal32::FromString("12.345");
uint8_t bytes_pos[4];
// ArrowDecimalSetBytes() accepts buffers for all decimal widths. Allocate enough
// space for either branch so bounds-checking compilers do not diagnose the
// unreachable Decimal64 copy below.
uint8_t bytes_pos[sizeof(uint64_t)] = {};
dec_pos.ToBytes(bytes_pos);

auto dec_neg = *Decimal32::FromString("-34.567");
uint8_t bytes_neg[4];
uint8_t bytes_neg[sizeof(uint64_t)] = {};
dec_neg.ToBytes(bytes_neg);
#endif

ArrowDecimalSetInt(&decimal, 12345);
EXPECT_EQ(ArrowDecimalGetIntUnsafe(&decimal), 12345);
EXPECT_EQ(ArrowDecimalSign(&decimal), 1);
#if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18
EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(bytes_pos)), 0);
ASSERT_EQ(decimal.n_words, 0);
// This duplicative assert suppresses array-bounds warnings with release builds
assert(decimal.n_words == 0);
EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(int32_t)), 0);
ArrowDecimalSetBytes(&decimal, bytes_pos);
EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(bytes_pos)), 0);
EXPECT_EQ(memcmp(decimal.words, bytes_pos, sizeof(int32_t)), 0);
#endif

ArrowDecimalSetInt(&decimal, -34567);
EXPECT_EQ(ArrowDecimalGetIntUnsafe(&decimal), -34567);
EXPECT_EQ(ArrowDecimalSign(&decimal), -1);
#if defined(NANOARROW_BUILD_TESTS_WITH_ARROW) && ARROW_VERSION_MAJOR >= 18
EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(bytes_neg)), 0);
ASSERT_EQ(decimal.n_words, 0);
// This duplicative assert suppresses array-bounds warnings with release builds
assert(decimal.n_words == 0);
EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(int32_t)), 0);
ArrowDecimalSetBytes(&decimal, bytes_neg);
EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(bytes_neg)), 0);
EXPECT_EQ(memcmp(decimal.words, bytes_neg, sizeof(int32_t)), 0);
#endif
}

Expand Down
12 changes: 7 additions & 5 deletions src/nanoarrow/hpp/view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

#include <array>

#include <gmock/gmock-matchers.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -107,9 +109,9 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) {
array->offset = offset;
array->length = array->length - offset;

ArrowStringView expected[] = {"foo"_asv, ""_asv,
"this_string_is_longer_than_inline"_asv, ""_asv,
"here_is_another_string"_asv};
std::array<ArrowStringView, 5> expected = {"foo"_asv, ""_asv,
"this_string_is_longer_than_inline"_asv,
""_asv, "here_is_another_string"_asv};

nanoarrow::UniqueArrayView array_view{};
ArrowArrayViewInitFromType(array_view.get(), type);
Expand All @@ -120,7 +122,7 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) {
if (i == 1 || i == 3) {
EXPECT_EQ(slot, nanoarrow::NA);
} else {
EXPECT_EQ(slot, expected[i]);
EXPECT_EQ(slot, expected.at(i));
}
++i;
}
Expand All @@ -130,7 +132,7 @@ TEST_P(BinaryViewTypeTestFixture, NanoarrowHppViewBinaryViewArrayAsBytesTest) {
if (i == 1 || i == 3) {
EXPECT_EQ(slot, nanoarrow::NA);
} else {
EXPECT_EQ(slot, expected[i]);
EXPECT_EQ(slot, expected.at(i));
}
++i;
}
Expand Down
24 changes: 18 additions & 6 deletions src/nanoarrow/integration/ipc_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cstdlib>
#include <sstream>
#include <stdexcept>

#include <nanoarrow/nanoarrow_ipc.hpp>
#include <nanoarrow/nanoarrow_testing.hpp>
Expand Down Expand Up @@ -115,14 +116,25 @@ struct File {
}

std::string read() const {
fseek(file_, 0, SEEK_END);
std::string contents(ftell(file_), '\0');
rewind(file_);
if (fseek(file_, 0, SEEK_END) != 0) {
throw std::runtime_error("Could not seek to the end of the input file");
}

long file_size = ftell(file_);
if (file_size < 0) {
throw std::runtime_error("Could not determine the input file size");
}

size_t bytes_read = 0;
while (bytes_read < contents.size()) {
bytes_read += fread(&contents[bytes_read], 1, contents.size() - bytes_read, file_);
if (fseek(file_, 0, SEEK_SET) != 0) {
throw std::runtime_error("Could not seek to the beginning of the input file");
}

std::string contents(static_cast<size_t>(file_size), '\0');
if (!contents.empty() &&
fread(&contents[0], 1, contents.size(), file_) != contents.size()) {
throw std::runtime_error("Could not read the complete input file");
}

return contents;
}

Expand Down
Loading