Skip to content
This repository was archived by the owner on Apr 22, 2019. It is now read-only.

Commit

Permalink
Variant map comparation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OlehKulykov committed Aug 19, 2015
1 parent d3ea576 commit 8867dca
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
6 changes: 4 additions & 2 deletions builds/mac/test_mac/test_mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
3D08311E1987CC1B0038CD79 /* libssl.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D08311D1987CC1B0038CD79 /* libssl.dylib */; };
3D0831251987CDE30038CD79 /* server-handshake.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D0831231987CDE30038CD79 /* server-handshake.c */; };
3D0831281987CE280038CD79 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D0831271987CE280038CD79 /* libcrypto.dylib */; };
3D6C153B1AAE61FF007E7310 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D08307E1987C9D80038CD79 /* main.m */; };
3D7450B31AAF90D400AA32A3 /* FCClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D7450B21AAF90D400AA32A3 /* FCClient.cpp */; };
3D7450B51AAF90DC00AA32A3 /* FCError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D7450B41AAF90DC00AA32A3 /* FCError.cpp */; };
3D7450B81AAF90EE00AA32A3 /* FCJsonUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D7450B71AAF90EE00AA32A3 /* FCJsonUtils.cpp */; };
Expand All @@ -70,6 +69,7 @@
3D7450C01AAF911500AA32A3 /* FCWebSocket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D7450BD1AAF911500AA32A3 /* FCWebSocket.cpp */; };
3D85BCC219F3DEA70057DAEC /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3D0830851987C9D80038CD79 /* AppDelegate.mm */; };
3DAD75F91A32F8900054F999 /* alloc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DAD75F81A32F8900054F999 /* alloc.c */; };
3DB6DCD21B847B0A00B0333C /* test_fayecpp_variantmessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DB6DCD11B847B0A00B0333C /* test_fayecpp_variantmessage.cpp */; };
3DE39A3D1A92247C00038C5A /* FayeCpp.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 3DE39A3C1A92247C00038C5A /* FayeCpp.bundle */; };
3DEE58781AEFC11600BA5B77 /* header.c in Sources */ = {isa = PBXBuildFile; fileRef = 3DEE58771AEFC11600BA5B77 /* header.c */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -172,6 +172,7 @@
3D7450BD1AAF911500AA32A3 /* FCWebSocket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FCWebSocket.cpp; path = ../../../../src/FCWebSocket.cpp; sourceTree = "<group>"; };
3D7450BE1AAF911500AA32A3 /* FCWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FCWebSocket.h; path = ../../../../src/FCWebSocket.h; sourceTree = "<group>"; };
3DAD75F81A32F8900054F999 /* alloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = alloc.c; path = ../../../../libwebsockets/lib/alloc.c; sourceTree = "<group>"; };
3DB6DCD11B847B0A00B0333C /* test_fayecpp_variantmessage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = test_fayecpp_variantmessage.cpp; path = ../../../../test/test_fayecpp_variantmessage.cpp; sourceTree = "<group>"; };
3DE39A3C1A92247C00038C5A /* FayeCpp.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = FayeCpp.bundle; path = ../../../../contrib/objc/FayeCpp.bundle; sourceTree = "<group>"; };
3DE39A3E1A9224C400038C5A /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/MainMenu.strings; sourceTree = "<group>"; };
3DE39A3F1A9224C400038C5A /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -388,6 +389,7 @@
3D3045DF19EE857D00D8B163 /* test */ = {
isa = PBXGroup;
children = (
3DB6DCD11B847B0A00B0333C /* test_fayecpp_variantmessage.cpp */,
3D3045E219EE88A600D8B163 /* test_fayecpp_init.cpp */,
3D3045E019EE859300D8B163 /* test_fayecpp_header.cpp */,
3D2739F01AAE0F0B00317CA3 /* test_fayecpp_connect.cpp */,
Expand Down Expand Up @@ -517,6 +519,7 @@
3D7450BF1AAF911500AA32A3 /* FCTransport.cpp in Sources */,
3D0830DB1987CB2D0038CD79 /* hashtable.c in Sources */,
3D08310F1987CB4E0038CD79 /* REStringUtilsPrivate.cpp in Sources */,
3DB6DCD21B847B0A00B0333C /* test_fayecpp_variantmessage.cpp in Sources */,
3D0830C11987CB160038CD79 /* extension-deflate-frame.c in Sources */,
3D0830E01987CB2D0038CD79 /* strbuffer.c in Sources */,
3D0830C21987CB160038CD79 /* extension-deflate-stream.c in Sources */,
Expand All @@ -543,7 +546,6 @@
3D0831151987CB4E0038CD79 /* REVariantMap.cpp in Sources */,
3D0830BC1987CB160038CD79 /* base64-decode.c in Sources */,
3D0831251987CDE30038CD79 /* server-handshake.c in Sources */,
3D6C153B1AAE61FF007E7310 /* main.m in Sources */,
3D0830C01987CB160038CD79 /* context.c in Sources */,
3D0830BD1987CB160038CD79 /* client-handshake.c in Sources */,
3D0830DF1987CB2D0038CD79 /* pack_unpack.c in Sources */,
Expand Down
6 changes: 5 additions & 1 deletion src/REVariantMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ namespace FayeCpp {

bool REVariantMap::isEqualToMap(const REVariantMap & map) const
{
REUInt32 srcCount = 0;
REVariantMap::Iterator i = this->iterator();
while (i.next())
{
srcCount++;
Node * node = map.findNode(i.key());
if (node)
{
Expand All @@ -125,7 +127,9 @@ namespace FayeCpp {
return false;
}
}
return true;

const REUInt32 dstCount = map.count();
return (srcCount == dstCount);
}

bool REVariantMap::operator==(const REVariantMap & map) const
Expand Down
94 changes: 94 additions & 0 deletions test/test_fayecpp_variantmessage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2014 - 2015 Kulykov Oleh <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#include <stdlib.h>
#include <assert.h>


#if defined(CMAKE_BUILD)
#undef CMAKE_BUILD
#endif

#if defined(__BUILDING_RECORE_DYNAMIC_LIBRARY__)
#undef __BUILDING_RECORE_DYNAMIC_LIBRARY__
#endif


#include <fayecpp.h>

using namespace FayeCpp;

int testVariantMessage1()
{
REVariant var1("Hello");

if (!var1.isEqualToVariant("Hello")) return 1;
if (var1.isEqualToVariant("Hello1")) return 2;

REVariantList list1;
list1 += 1;
list1 += true;

REVariantList list2;
list2 += true;
list2 += 1;

if (!list1.isEqualToList(list2)) return 3;
var1 = list1;
REVariant var2 = list2;

if (var1.isEqualToVariant("das")) return 4;
if (var1.isEqualToVariant(true)) return 5;
if (!var1.isEqualToVariant(var2)) return 6;

list2 += 3;
if (list1.isEqualToList(list2)) return 7;

list2.clear();
if (list1.isEqualToList(list2)) return 8;


REVariantMap map1, map2;
map1["k1"] = true;
map2["k1"] = true;
if (!map1.isEqualToMap(map2)) return 9;
map2["k2"] = 45;
if (map1.isEqualToMap(map2)) return 10;

return EXIT_SUCCESS;
}

int main(int argc, char* argv[])
{
RELog::log("Client info: %s", Client::info());
RELog::log("Start test");


RELog::log("Test test variant message #1 ...");
int test = testVariantMessage1();
assert(test == EXIT_SUCCESS);
RELog::log("Test test variant message #1 OK");

RELog::log("All done.");
return EXIT_SUCCESS;
}

0 comments on commit 8867dca

Please sign in to comment.