2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file test_value_separated_reader.cpp
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
19 * @brief tests for VSReader
22 #include<dpl/test/value_separated_reader.h>
23 #include<dpl/abstract_input.h>
24 #include<dpl/test/test_runner.h>
30 RUNNER_TEST_GROUP_INIT(ValueSeparatedReader)
32 RUNNER_TEST(ValueSeparatedReader_readValidCSV)
35 data += "1-1,1-2,1-3,1-4\n";
36 data += "2-1,2-2,2-3,2-4\n";
37 data += "3-1,3-2,3-3,3-4\n";
38 data += "4-1,4-2,4-3,4-4\n";
39 std::shared_ptr<AbstractInput> mem(new BinaryQueue());
40 dynamic_cast<BinaryQueue*>(mem.get())->AppendCopy(data.data(), data.size());
42 VSResultPtr result = csv.ReadInput();
43 RUNNER_ASSERT_MSG((*result)[0][0] == "1-1", "Wrong value");
44 RUNNER_ASSERT_MSG((*result)[0][1] == "1-2", "Wrong value");
45 RUNNER_ASSERT_MSG((*result)[0][2] == "1-3", "Wrong value");
46 RUNNER_ASSERT_MSG((*result)[0][3] == "1-4", "Wrong value");
48 RUNNER_ASSERT_MSG((*result)[1][0] == "2-1", "Wrong value");
49 RUNNER_ASSERT_MSG((*result)[1][1] == "2-2", "Wrong value");
50 RUNNER_ASSERT_MSG((*result)[1][2] == "2-3", "Wrong value");
51 RUNNER_ASSERT_MSG((*result)[1][3] == "2-4", "Wrong value");
53 RUNNER_ASSERT_MSG((*result)[2][0] == "3-1", "Wrong value");
54 RUNNER_ASSERT_MSG((*result)[2][1] == "3-2", "Wrong value");
55 RUNNER_ASSERT_MSG((*result)[2][2] == "3-3", "Wrong value");
56 RUNNER_ASSERT_MSG((*result)[2][3] == "3-4", "Wrong value");
58 RUNNER_ASSERT_MSG((*result)[3][0] == "4-1", "Wrong value");
59 RUNNER_ASSERT_MSG((*result)[3][1] == "4-2", "Wrong value");
60 RUNNER_ASSERT_MSG((*result)[3][2] == "4-3", "Wrong value");
61 RUNNER_ASSERT_MSG((*result)[3][3] == "4-4", "Wrong value");
64 RUNNER_TEST(ValueSeparatedReader_readInvalidCSV)
69 data += "1-1,1-2,1-3,1-4\n";
70 data += "2-1,2-2,2-3,2-4\n";
71 data += "3-1,3-2,3-3\n";
72 data += "4-1,4-2,4-3,4-4\n";
73 std::shared_ptr<AbstractInput> mem(new BinaryQueue());
74 dynamic_cast<BinaryQueue*>(mem.get())->AppendCopy(data.data(), data.size());
76 VSResultPtr result = csv.ReadInput();
78 Catch(CSVReader::Exception::ParserError)
82 RUNNER_ASSERT_MSG(false, "Should throw parser error");