From da8adaab39bb502b674672e34515395dd600497a Mon Sep 17 00:00:00 2001 From: fbraem Date: Wed, 18 Nov 2015 18:57:11 +0100 Subject: [PATCH] Add testHMGET --- Redis/testsuite/src/RedisTest.cpp | 53 +++++++++++++++++++++++++++++++ Redis/testsuite/src/RedisTest.h | 1 + 2 files changed, 54 insertions(+) diff --git a/Redis/testsuite/src/RedisTest.cpp b/Redis/testsuite/src/RedisTest.cpp index efc31e48c..300654f89 100644 --- a/Redis/testsuite/src/RedisTest.cpp +++ b/Redis/testsuite/src/RedisTest.cpp @@ -618,6 +618,58 @@ void RedisTest::testHKEYS() } } +void RedisTest::testHMGET() +{ + if (!_connected) + { + std::cout << "Not connected, test skipped." << std::endl; + return; + } + + delKey("myhash"); + + Command hset = Command::hset("myhash", "field1", "Hello"); + try + { + Poco::Int64 value = _redis.execute(hset); + assert(value == 1); + } + catch(RedisException &e) + { + fail(e.message()); + } + + hset = Command::hset("myhash", "field2", "World"); + try + { + Poco::Int64 value = _redis.execute(hset); + assert(value == 1); + } + catch(RedisException &e) + { + fail(e.message()); + } + + std::vector fields; + fields.push_back("field1"); + fields.push_back("field2"); + fields.push_back("field3"); + Command hmget = Command::hmget("myhash", fields); + try + { + Array result = _redis.execute(hmget); + assert(result.size() == 3); + + assert(result.get(0).value().compare("Hello") == 0); + assert(result.get(1).value().compare("World") == 0); + assert(result.get(2).isNull()); + } + catch(RedisException &e) + { + fail(e.message()); + } +} + void RedisTest::testHSET() { if (!_connected) @@ -2687,6 +2739,7 @@ CppUnit::Test* RedisTest::suite() CppUnit_addTest(pSuite, RedisTest, testHGETALL); CppUnit_addTest(pSuite, RedisTest, testHINCRBY); CppUnit_addTest(pSuite, RedisTest, testHKEYS); + CppUnit_addTest(pSuite, RedisTest, testHMGET); CppUnit_addTest(pSuite, RedisTest, testHSET); CppUnit_addTest(pSuite, RedisTest, testINCR); CppUnit_addTest(pSuite, RedisTest, testINCRBY); diff --git a/Redis/testsuite/src/RedisTest.h b/Redis/testsuite/src/RedisTest.h index affbd62a7..3119c964c 100644 --- a/Redis/testsuite/src/RedisTest.h +++ b/Redis/testsuite/src/RedisTest.h @@ -42,6 +42,7 @@ public: void testHGETALL(); void testHINCRBY(); void testHKEYS(); + void testHMGET(); void testHSET(); void testINCR(); void testINCRBY();