mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 22:52:31 +00:00
* More work on rpc::object_storage and moving simple functions over to it.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1165 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -18,6 +18,8 @@ rtorrentTest_SOURCES = \
|
||||
rpc/command_slot_test.h \
|
||||
rpc/object_storage_test.cc \
|
||||
rpc/object_storage_test.h \
|
||||
src/command_dynamic_test.cc \
|
||||
src/command_dynamic_test.h \
|
||||
main.cc
|
||||
|
||||
rtorrentTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
|
||||
|
||||
@@ -13,14 +13,14 @@ ObjectStorageTest::test_basics() {
|
||||
|
||||
CPPUNIT_ASSERT(m_storage.empty());
|
||||
|
||||
itr = m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_generic_type);
|
||||
itr = m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_string_type);
|
||||
|
||||
CPPUNIT_ASSERT(itr != m_storage.end());
|
||||
CPPUNIT_ASSERT(&*itr != NULL);
|
||||
CPPUNIT_ASSERT(itr->first.size() == 6 && std::strcmp(itr->first.data(), "test_1") == 0);
|
||||
CPPUNIT_ASSERT(itr->second.object.is_string() && itr->second.object.as_string() == "a");
|
||||
|
||||
ASSERT_CATCH_INPUT_ERROR( { m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_generic_type); } );
|
||||
ASSERT_CATCH_INPUT_ERROR( { m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_string_type); } );
|
||||
|
||||
// Test erase.
|
||||
m_storage.erase(rpc::object_storage::key_type::from_c_str("test_1"));
|
||||
@@ -35,13 +35,13 @@ ObjectStorageTest::test_basics() {
|
||||
|
||||
void
|
||||
ObjectStorageTest::test_conversions() {
|
||||
CPPUNIT_ASSERT(m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_generic_type) != m_storage.end());
|
||||
CPPUNIT_ASSERT(m_storage.insert_string(std::string("test_2"), torrent::Object("a"), rpc::object_storage::flag_generic_type) != m_storage.end());
|
||||
CPPUNIT_ASSERT(m_storage.insert("test_1", torrent::Object("a"), rpc::object_storage::flag_string_type) != m_storage.end());
|
||||
CPPUNIT_ASSERT(m_storage.insert_str(std::string("test_2"), torrent::Object("a"), rpc::object_storage::flag_string_type) != m_storage.end());
|
||||
|
||||
char raw_3[8] = "test_3\x1";
|
||||
torrent::raw_string raw_string_3(raw_3, 6);
|
||||
|
||||
CPPUNIT_ASSERT(m_storage.insert(raw_string_3, torrent::Object("a"), rpc::object_storage::flag_generic_type)->first == std::string("test_3"));
|
||||
CPPUNIT_ASSERT(m_storage.insert(raw_string_3, torrent::Object("a"), rpc::object_storage::flag_string_type)->first == std::string("test_3"));
|
||||
m_storage.clear();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void
|
||||
ObjectStorageTest::test_validate_keys() {
|
||||
torrent::raw_string raw_string_4("test_4\0foo", 10);
|
||||
|
||||
ASSERT_CATCH_INPUT_ERROR( { m_storage.insert(raw_string_4, torrent::Object("a"), rpc::object_storage::flag_generic_type); } );
|
||||
ASSERT_CATCH_INPUT_ERROR( { m_storage.insert(raw_string_4, torrent::Object("a"), rpc::object_storage::flag_string_type); } );
|
||||
}
|
||||
|
||||
// And test many other bad/good string combos.
|
||||
@@ -58,20 +58,20 @@ ObjectStorageTest::test_validate_keys() {
|
||||
|
||||
void
|
||||
ObjectStorageTest::test_access() {
|
||||
m_storage.insert("generic_1", torrent::Object("gen_a"), rpc::object_storage::flag_generic_type);
|
||||
m_storage.insert("string_1", torrent::Object("gen_a"), rpc::object_storage::flag_string_type);
|
||||
m_storage.insert("value_1", int64_t(1), rpc::object_storage::flag_value_type);
|
||||
|
||||
CPPUNIT_ASSERT(m_storage.get_c_str("generic_1").as_string() == "gen_a");
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str("generic_1", int64_t(1)).as_value() == 1);
|
||||
CPPUNIT_ASSERT(m_storage.get_c_str("string_1").as_string() == "gen_a");
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str_string("string_1", "test").as_string() == "test");
|
||||
|
||||
// Test value from raw and normal, list, etc.
|
||||
CPPUNIT_ASSERT(m_storage.get_c_str("value_1").as_value() == 1);
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str("value_1", int64_t(2)).as_value() == 2);
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str("value_1", "123").as_value() == 123);
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str("value_1", torrent::raw_string::from_c_str("321")).as_value() == 321);
|
||||
// CPPUNIT_ASSERT(m_storage.set_c_str("value_1", torrent::raw_bencode::from_c_str("i567e")).as_value() == 567);
|
||||
|
||||
ASSERT_CATCH_INPUT_ERROR( { m_storage.set_c_str("value_1", "e123"); } );
|
||||
CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", int64_t(2)).as_value() == 2);
|
||||
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", "123").as_value() == 123);
|
||||
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", torrent::raw_string::from_c_str("321")).as_value() == 321);
|
||||
// CPPUNIT_ASSERT(m_storage.set_c_str_value("value_1", torrent::raw_bencode::from_c_str("i567e")).as_value() == 567);
|
||||
|
||||
// ASSERT_CATCH_INPUT_ERROR( { m_storage.set_c_str_value("value_1", "e123"); } );
|
||||
|
||||
// Test string from raw and normal, list, etc.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#import "command_dynamic_test.h"
|
||||
|
||||
#include "rpc/parse_commands.h"
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(CommandDynamicTest);
|
||||
|
||||
#define ASSERT_CATCH_INPUT_ERROR(some_code) \
|
||||
try { some_code; CPPUNIT_ASSERT("torrent::input_error not caught" && false); } catch (torrent::input_error& e) { }
|
||||
|
||||
void initialize_command_dynamic();
|
||||
void initialize_command_ui();
|
||||
|
||||
void
|
||||
CommandDynamicTest::setUp() {
|
||||
if (rpc::commands.empty()) {
|
||||
setlocale(LC_ALL, "");
|
||||
cachedTime = rak::timer::current();
|
||||
control = new Control;
|
||||
|
||||
initialize_command_dynamic();
|
||||
initialize_command_ui();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CommandDynamicTest::test_basics() {
|
||||
rpc::commands.call_command("method.insert.value", rpc::create_object_list("test_basics.1", int64_t(1)));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_basics.1", torrent::Object()).as_value() == 1);
|
||||
}
|
||||
|
||||
void
|
||||
CommandDynamicTest::test_get_set() {
|
||||
rpc::commands.call_command("method.insert.simple", rpc::create_object_list("test_get_set.1", "cat=1"));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_get_set.1", torrent::Object()).as_string() == "1");
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("method.get", "test_get_set.1").as_string() == "cat=1");
|
||||
|
||||
rpc::commands.call_command("method.set", rpc::create_object_list("test_get_set.1", "cat=2"));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("method.get", "test_get_set.1").as_string() == "cat=2");
|
||||
}
|
||||
|
||||
void
|
||||
CommandDynamicTest::test_old_style() {
|
||||
rpc::commands.call_command("method.insert", rpc::create_object_list("test_old_style.1", "value", int64_t(1)));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_old_style.1", torrent::Object()).as_value() == 1);
|
||||
|
||||
rpc::commands.call_command("method.insert", rpc::create_object_list("test_old_style.2", "bool", int64_t(5)));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_old_style.2", torrent::Object()).as_value() == 1);
|
||||
|
||||
rpc::commands.call_command("method.insert", rpc::create_object_list("test_old_style.3", "string", "test.2"));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_old_style.3", torrent::Object()).as_string() == "test.2");
|
||||
|
||||
rpc::commands.call_command("method.insert", rpc::create_object_list("test_old_style.4", "simple", "cat=test.3"));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_old_style.4", torrent::Object()).as_string() == "test.3");
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class CommandDynamicTest : public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(CommandDynamicTest);
|
||||
CPPUNIT_TEST(test_basics);
|
||||
CPPUNIT_TEST(test_get_set);
|
||||
CPPUNIT_TEST(test_old_style);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp();
|
||||
void tearDown() {}
|
||||
|
||||
void test_basics();
|
||||
void test_get_set();
|
||||
|
||||
void test_old_style();
|
||||
|
||||
private:
|
||||
};
|
||||
Reference in New Issue
Block a user