27 using namespace basis;
37 #define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s)
51 #define COMPLAIN_FIELD(list, index, value) \
52 ASSERT_EQUAL(list[index], astring(value), \
53 a_sprintf("comparison test should have field %d correct in %s", index, #list))
55 int test_parsing_csv::execute()
58 astring line1 =
"\"fupe\",\"snoorp\",\"lutem\",\"fipe\"";
60 bool works1 = list_parsing::parse_csv_line(line1, fields1);
61 ASSERT_TRUE(works1,
"first test should not fail to parse");
63 ASSERT_EQUAL(fields1.
length(), 4,
"first test should have right count of strings found");
69 astring line2 =
"fupe,\"snoorp\",lutem,\"fipe\"";
71 bool works2 = list_parsing::parse_csv_line(line2, fields2);
72 ASSERT_TRUE(works2,
"second test should not fail to parse");
73 ASSERT_EQUAL(fields2.
length(), 4,
"second test should have right count of strings found");
79 astring line3 =
"\"lowenburger\",\"wazizzle\",morphel";
81 bool works3 = list_parsing::parse_csv_line(line3, fields3);
82 ASSERT_TRUE(works3,
"third test should not fail to parse");
83 ASSERT_EQUAL(fields3.
length(), 3,
"third test should have right count of strings found");
88 astring line4 =
"\"lowenburger\",\"wazizzle\",morphel,";
90 bool works4 = list_parsing::parse_csv_line(line4, fields4);
91 ASSERT_TRUE(works4,
"fourth test should not fail to parse");
92 ASSERT_EQUAL(fields4.
length(), 4,
"fourth test should not have wrong count of strings found");
98 astring line5 =
"\"lowenburger\",,";
100 bool works5 = list_parsing::parse_csv_line(line5, fields5);
101 ASSERT_TRUE(works5,
"fifth test should not fail to parse");
102 ASSERT_EQUAL(fields5.
length(), 3,
"fifth test should have right count of strings found");
107 astring line6 =
",,,\"rasputy\",,\"spunk\",ralph";
109 bool works6 = list_parsing::parse_csv_line(line6, fields6);
110 ASSERT_TRUE(works6,
"sixth test should not fail to parse");
111 ASSERT_EQUAL(fields6.
length(), 7,
"sixth test should have right count of strings found");
120 astring line7 =
"\"SRV0001337CHN0000001DSP0000001SRV0001337LAY0003108,16,0,8,192\",\"\\\"row_3\\\" on 12.5.55.159\",3";
122 bool works7 = list_parsing::parse_csv_line(line7, fields7);
123 ASSERT_TRUE(works7,
"seventh test should not fail to parse");
124 ASSERT_EQUAL(fields7.
length(), 3,
"seventh test should have right count of strings found");
125 COMPLAIN_FIELD(fields7, 0,
"SRV0001337CHN0000001DSP0000001SRV0001337LAY0003108,16,0,8,192");
136 while ( (read_result = test_data.
getline(curr_line, 1024)) > 0 )
143 for (
int line = 0; line < lines.
length(); line++) {
144 const astring ¤t = lines[line];
145 list_parsing::parse_csv_line(current, parsed);
149 log(
a_sprintf(
"%d csv lines with %d iterations took %d ms (or %d s).",
156 fields9 +=
"ACk\"boozort";
157 fields9 +=
"sme\"ra\"\"foop";
158 fields9 +=
"\"gumby\"";
159 astring line9 =
"\"ACk\\\"boozort\",\"sme\\\"ra\\\"\\\"foop\",\"\\\"gumby\\\"\"";
161 list_parsing::create_csv_line(fields9, gen_line_9);
164 ASSERT_EQUAL(gen_line_9, line9,
"ninth test should not fail to create expected text");
166 bool works9 = list_parsing::parse_csv_line(gen_line_9, fields9_b);
167 ASSERT_TRUE(works9,
"ninth test should not fail to parse");
168 ASSERT_TRUE(fields9_b == fields9,
"ninth test should match original fields");
170 return final_report();
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
Provides file managment services using the standard I/O support.
int getline(basis::abyte *buffer, int desired_size)
reads a line of text (terminated by a return) into the "buffer".
Provides operations commonly needed on file names.
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
filename dirname() const
returns the directory for the filename.
An array of strings with some additional helpful methods.
A class for measuring event durations in real time.
void stop()
a synonym for halt().
int elapsed()
a synonym for milliseconds().
void start()
Begins the timing.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
#define COMPLAIN_FIELD(list, index, value)
const int MAX_DATA_FILE_ITERS
#define ASSERT_EQUAL(a, b, test_name)
#define ASSERT_TRUE(a, test_name)