Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / testframework / unittests / libs / TEST_utils.cpp
1 #include "utils.h"
2
3 #include <vector>
4 #include <stdio.h>
5 #include <string.h>
6
7 #include "easyunit/test.h"
8
9 TEST(UtilsTest,split)
10 {
11 const char *s= "one two three";
12 std::vector<std::string> v= split(s, ' ');
13 ASSERT_TRUE(v.size() == 3);
14 ASSERT_TRUE(v[0] == "one");
15 ASSERT_TRUE(v[1] == "two");
16 ASSERT_TRUE(v[2] == "three");
17 }
18
19 TEST(UtilsTest,split_empty_string)
20 {
21 const char *s= "";
22 std::vector<std::string> v= split(s, ' ');
23
24 ASSERT_TRUE(v.size() == 1);
25 ASSERT_TRUE(v[0].empty());
26 ASSERT_TRUE(v[0] == "");
27 }
28
29 TEST(UtilsTest,parse_number_list)
30 {
31 const char *s= "1.1,2.2,3.3";
32 std::vector<float> v= parse_number_list(s);
33 ASSERT_TRUE(v.size() == 3);
34 ASSERT_TRUE(v[0] == 1.1F);
35 ASSERT_TRUE(v[1] == 2.2F);
36 ASSERT_TRUE(v[2] == 3.3F);
37 }
38
39 TEST(UtilsTest,append_parameters)
40 {
41 char buf[132];
42
43 int n= append_parameters(buf, {{'X', 1}, {'Y', 2}, {'Z', 3}}, sizeof(buf));
44 //printf("%d - %s\n", n, buf);
45 ASSERT_TRUE(n == 24);
46 ASSERT_TRUE(strcmp(buf, "X1.0000 Y2.0000 Z3.0000 ") == 0);
47 }