• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1921 (tree)
日時2010-09-20 04:49:40
作者satofumi

ログメッセージ

connection_utilities.c のテストを追加。テスト通過

変更サマリ

差分

--- branches/tsukuba_2010/libs/unittest/all_test.cpp (nonexistent)
+++ branches/tsukuba_2010/libs/unittest/all_test.cpp (revision 1921)
@@ -0,0 +1,41 @@
1+#include <string>
2+#include <cppunit/TestResult.h>
3+#include <cppunit/TestResultCollector.h>
4+#include <cppunit/TextTestProgressListener.h>
5+#include <cppunit/BriefTestProgressListener.h>
6+#include <cppunit/ui/text/TestRunner.h>
7+#include <cppunit/CompilerOutputter.h>
8+#include <cppunit/extensions/HelperMacros.h>
9+#include <stdexcept>
10+#include <iostream>
11+
12+using namespace std;
13+
14+
15+int main(int argc, char *argv[])
16+{
17+ static_cast<void>(argc);
18+ static_cast<void>(argv);
19+
20+ CPPUNIT_NS::TestResult controller;
21+
22+ CPPUNIT_NS::TestResultCollector result;
23+ controller.addListener(&result);
24+
25+ //CPPUNIT_NS::TextTestProgressListener progress;
26+ CPPUNIT_NS::BriefTestProgressListener progress;
27+ controller.addListener(&progress);
28+
29+ CPPUNIT_NS::TestRunner runner;
30+ runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
31+
32+ runner.run(controller, "");
33+
34+ CPPUNIT_NS::CompilerOutputter outputter(&result, cerr);
35+ outputter.write();
36+
37+#if defined(_MSC_VER)
38+ getchar();
39+#endif
40+ return result.wasSuccessful() ? 0 : 1;
41+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/connection_utilities.c (revision 1920)
+++ branches/tsukuba_2010/libs/run_drive/connection_utilities.c (revision 1921)
@@ -32,7 +32,7 @@
3232 } else {
3333 int ret_value = line_buffer_filled_;
3434 memcpy(data, line_buffer_, line_buffer_filled_);
35- data[line_buffer_filled_] = '\n';
35+ data[line_buffer_filled_] = '\0';
3636 line_buffer_filled_ = 0;
3737 return ret_value;
3838 }
--- branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.h (revision 1921)
@@ -0,0 +1,27 @@
1+#ifndef QRK_CONNECTION_UTILITIES_TEST_H
2+#define QRK_CONNECTION_UTILITIES_TEST_H
3+
4+/*!
5+ \file
6+ \brief connection_utilities.c のテスト
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include <cppunit/extensions/HelperMacros.h>
14+
15+
16+//! connection_utilities.c のテストクラス
17+class Connection_utilities_test : public CppUnit::TestFixture
18+{
19+ CPPUNIT_TEST_SUITE(Connection_utilities_test);
20+ CPPUNIT_TEST(readline_test);
21+ CPPUNIT_TEST_SUITE_END();
22+
23+public:
24+ void readline_test(void);
25+};
26+
27+#endif /* !QRK_CONNECTION_UTILITIES_TEST_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/host_connection.h (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/host_connection.h (revision 1921)
@@ -0,0 +1,21 @@
1+#ifndef QRK_HOST_CONNECTION_H
2+#define QRK_HOST_CONNECTION_H
3+
4+/*!
5+ \file
6+ \brief ダミーセンサ用の PC 向け送受信関数
7+
8+ 実装は connection_dummy.cpp が提供する。
9+
10+ \author Satofumi KAMIMURA
11+
12+ $Id$
13+*/
14+
15+#include <string>
16+
17+
18+extern void send_command(const char *command);
19+extern std::string receive_response_line(void);
20+
21+#endif /* !QRK_HOST_CONNECTION_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.cpp (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/Connection_utilities_test.cpp (revision 1921)
@@ -0,0 +1,42 @@
1+/*!
2+ \file
3+ \brief CONNECTION_UTILITIES のテスト
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "Connection_utilities_test.h"
11+#include "connection_utilities.h"
12+#include "host_connection.h"
13+#include "connection.h"
14+#include <string>
15+
16+using namespace std;
17+
18+CPPUNIT_TEST_SUITE_REGISTRATION(Connection_utilities_test);
19+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Connection_utilities_test,
20+ "Connection_utilities_test");
21+
22+
23+void Connection_utilities_test::readline_test(void)
24+{
25+ connection_initialize();
26+
27+ // 改行までの文字列が返されるかのテスト
28+ send_command("a\n");
29+ char buffer[CONNECTION_READLINE_BUFFER_SIZE];
30+ int n =connection_readline(buffer, CONNECTION_READLINE_BUFFER_SIZE);
31+ CPPUNIT_ASSERT_EQUAL(1, n);
32+ CPPUNIT_ASSERT_EQUAL(string("a"), string(buffer));
33+
34+ // データがないときの読み出しが -1 を返すかのテスト
35+ n =connection_readline(buffer, CONNECTION_READLINE_BUFFER_SIZE);
36+ CPPUNIT_ASSERT_EQUAL(-1, n);
37+
38+ // 改行のみのときの読み出しがゼロを返すかのテスト
39+ send_command("\n");
40+ n =connection_readline(buffer, CONNECTION_READLINE_BUFFER_SIZE);
41+ CPPUNIT_ASSERT_EQUAL(0, n);
42+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/connection_dummy.cpp (nonexistent)
+++ branches/tsukuba_2010/libs/run_drive/test/connection_dummy.cpp (revision 1921)
@@ -0,0 +1,91 @@
1+/*!
2+ \example connection_dummy.cpp connection.c のダミー実装
3+
4+ \author Satofumi KAMIMURA
5+
6+ $Id$
7+*/
8+
9+#include "connection.h"
10+#include <deque>
11+#include <string>
12+#include <cstring>
13+
14+using namespace std;
15+
16+
17+namespace
18+{
19+ deque<char> pc_sent_command_;
20+ deque<char> sensor_sent_data_;
21+ string sensor_sent_buffer_;
22+}
23+
24+
25+void send_command(const char *command)
26+{
27+ size_t n = strlen(command);
28+ for (size_t i = 0; i < n; ++i) {
29+ pc_sent_command_.push_back(command[i]);
30+ }
31+}
32+
33+
34+std::string receive_response_line(void)
35+{
36+ // 改行を送信したら、そこまでを1行の終端として処理する
37+ size_t n = sensor_sent_data_.size();
38+ string line;
39+ for (size_t i = 0; i < n; ++i) {
40+ char front_ch = sensor_sent_data_.front();
41+ line.push_back(front_ch);
42+ sensor_sent_data_.pop_front();
43+
44+ if (front_ch == '\n') {
45+ break;
46+ }
47+ }
48+ return line;
49+}
50+
51+
52+void connection_initialize(void)
53+{
54+ pc_sent_command_.clear();
55+ sensor_sent_data_.clear();
56+}
57+
58+
59+int connection_write(const char *data, int data_size)
60+{
61+ for (int i = 0; i < data_size; ++i) {
62+ sensor_sent_buffer_.push_back(data[i]);
63+ }
64+ return data_size;
65+}
66+
67+
68+void connection_write_flush(void)
69+{
70+ size_t n = sensor_sent_buffer_.size();
71+ for (size_t i = 0; i < n; ++i) {
72+ sensor_sent_data_.push_back(sensor_sent_buffer_[i]);
73+ }
74+ sensor_sent_buffer_.clear();
75+}
76+
77+
78+int connection_read(char *data, int max_data_size)
79+{
80+ size_t read_size =
81+ min(static_cast<size_t>(max_data_size), pc_sent_command_.size());
82+
83+ for (size_t i = 0; i < read_size; ++i) {
84+ char ch = pc_sent_command_.front();
85+ data[i] = ch;
86+
87+ pc_sent_command_.pop_front();
88+ }
89+
90+ return read_size;
91+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- branches/tsukuba_2010/libs/run_drive/test/Makefile (revision 1920)
+++ branches/tsukuba_2010/libs/run_drive/test/Makefile (revision 1921)
@@ -6,7 +6,7 @@
66
77 TARGET = wheel_velocity_test
88
9-all : $(TARGET)
9+all : $(TARGET) test
1010
1111 clean :
1212 $(RM) $(TARGET) *.o
@@ -14,6 +14,24 @@
1414 depend :
1515 makedepend -Y -- $(INCLUDES) -- $(wildcard *.h *.cpp)
1616
17+test : all_test
18+ ./all_test
19+
20+######################################################################
21+TEST_OBJS = all_test.o Connection_utilities_test.o connection_dummy.o connection_utilities.o std_string.o
22+
23+all_test : $(TEST_OBJS)
24+ $(CXX) $(CXXFLAGS) $(TEST_OBJS) -o $@ `cppunit-config --libs` $(TEST_LDLIBS)
25+
26+all_test.o : ../../unittest/all_test.cpp
27+ $(CXX) $(CXXFLAGS) `cppunit-config --cflags` $< -c -o $@
28+
29+connection_utilities.o : ../connection_utilities.c
30+ $(CXX) $(CXXFLAGS) $< -c -o $@
31+
32+std_string.o : ../std_string.c
33+ $(CXX) $(CXXFLAGS) $< -c -o $@
34+
1735 # DO NOT DELETE
1836
1937 wheel_velocity_test.o: ../wheel_velocity.c ../wheel_velocity.h ../wheel_t.h
旧リポジトリブラウザで表示