Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test that field names do not have to be unique #160

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
51 changes: 51 additions & 0 deletions tests/dbf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,57 @@ TEST(DBFFieldTest, SetAndGetLogicalInvalid)
fs::remove(filename);
}

static auto WriteDuplicateFields(const fs::path &filename) -> auto
{
const auto handle = DBFCreate(filename.string().c_str());
EXPECT_NE(nullptr, handle);
const auto fid1 = DBFAddField(handle, "field", FTDate, 8, 0);
EXPECT_GE(fid1, 0);
const auto fid2 = DBFAddField(handle, "field", FTDate, 8, 0);
EXPECT_GE(fid2, 0);
const auto fid3 = DBFAddField(handle, "field", FTDouble, 8, 5);
EXPECT_GE(fid3, 0);
const auto fid4 = DBFAddField(handle, "field", FTDouble, 8, 10);
EXPECT_GE(fid4, 0);
const auto fid5 = DBFAddField(handle, "field", FTInteger, 8, 0);
EXPECT_GE(fid5, 0);
const auto fid6 = DBFAddField(handle, "field", FTInteger, 8, 0);
EXPECT_GE(fid6, 0);
const auto fid7 = DBFAddField(handle, "field", FTLogical, 1, 0);
EXPECT_GE(fid7, 0);
const auto fid8 = DBFAddField(handle, "field", FTLogical, 1, 0);
EXPECT_GE(fid8, 0);
const auto fid9 = DBFAddField(handle, "field", FTString, 5, 0);
EXPECT_GE(fid9, 0);
const auto fid0 = DBFAddField(handle, "field", FTString, 10, 0);
EXPECT_GE(fid0, 0);
const auto nFields = DBFGetFieldCount(handle);
EXPECT_EQ(nFields, 10);
DBFClose(handle);
}

static auto ReadDuplicateFields(const fs::path &filename) -> auto
{
const auto handle = DBFOpen(filename.string().c_str(), "r");
EXPECT_NE(nullptr, handle);
const auto nFields = DBFGetFieldCount(handle);
EXPECT_EQ(nFields, 10);
const auto fid = DBFGetFieldIndex(handle, "field");
EXPECT_EQ(fid, 0);
DBFClose(handle);
}

TEST(DBFFieldTest, AddDuplicateField)
{
const auto filename =
fs::temp_directory_path() / GenerateUniqueFilename(".dbf");
WriteDuplicateFields(filename);
const auto size = fs::file_size(filename);
EXPECT_EQ(354, size);
ReadDuplicateFields(filename);
fs::remove(filename);
}

} // namespace

int main(int argc, char **argv)
Expand Down