]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1603] UT CSVFileTest.parseContentWithBlankLines
authorAndrei Pavel <andrei@isc.org>
Mon, 4 Jan 2021 16:07:11 +0000 (18:07 +0200)
committerAndrei Pavel <andrei@isc.org>
Mon, 4 Jan 2021 17:43:53 +0000 (17:43 +0000)
src/lib/util/tests/csv_file_unittest.cc

index 17c2161db879e385f38fefa0159fd34b5a977724..d485f007c8493fd97b59374b7dcbee2ff9c6c29b 100644 (file)
@@ -640,4 +640,61 @@ TEST_F(CSVFileTest, parseContentWithoutTrailingBlankLine) {
     csv.close();
 }
 
+// Check that blank lines are skipped when reading from a file.
+TEST_F(CSVFileTest, parseContentWithBlankLines) {
+    for (std::string const& content : {
+        // Single intermediary blank line
+        "animal,age,color\n"
+        "cat,4,white\n"
+        "\n"
+        "lion,8,yellow\n",
+
+        // Blank lines all over
+        "\n"
+        "\n"
+        "animal,age,color\n"
+        "\n"
+        "\n"
+        "cat,4,white\n"
+        "\n"
+        "\n"
+        "lion,8,yellow\n"
+        "\n"
+        "\n",
+    }) {
+        // Create a new CSV file.
+        writeFile(content);
+
+        // Open this file and check that the header is parsed.
+        CSVFile csv(testfile_);
+        ASSERT_NO_THROW(csv.open());
+        ASSERT_EQ(3, csv.getColumnCount());
+        EXPECT_EQ("animal", csv.getColumnName(0));
+        EXPECT_EQ("age", csv.getColumnName(1));
+        EXPECT_EQ("color", csv.getColumnName(2));
+
+        // Check the first data row.
+        CSVRow row;
+        ASSERT_TRUE(csv.next(row));
+        EXPECT_EQ("cat", row.readAt(0));
+        EXPECT_EQ("4", row.readAt(1));
+        EXPECT_EQ("white", row.readAt(2));
+        EXPECT_EQ("success", csv.getReadMsg());
+
+        // Check the second non-blank data row.
+        ASSERT_TRUE(csv.next(row));
+        EXPECT_EQ("lion", row.readAt(0));
+        EXPECT_EQ("8", row.readAt(1));
+        EXPECT_EQ("yellow", row.readAt(2));
+        EXPECT_EQ("success", csv.getReadMsg());
+
+        // Attempt to read the next row which doesn't exist.
+        ASSERT_TRUE(csv.next(row));
+        EXPECT_EQ(CSVFile::EMPTY_ROW(), row);
+
+        // Close the file.
+        csv.close();
+    }
+}
+
 } // end of anonymous namespace