From 4d3356dc1e1239d8f4fb985d2f584a403aea8521 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 16 Sep 2016 17:02:43 -0700 Subject: [PATCH] [tests] Add tests for Map::[add|remove]Image --- test/fixtures/api/icon_style.json | 25 ++++++++++++++++ test/fixtures/map/add_icon/expected.png | Bin 0 -> 1741 bytes test/fixtures/map/remove_icon/expected.png | Bin 0 -> 355 bytes test/map/map.cpp | 33 +++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 test/fixtures/api/icon_style.json create mode 100644 test/fixtures/map/add_icon/expected.png create mode 100644 test/fixtures/map/remove_icon/expected.png diff --git a/test/fixtures/api/icon_style.json b/test/fixtures/api/icon_style.json new file mode 100644 index 000000000..17d41c6b6 --- /dev/null +++ b/test/fixtures/api/icon_style.json @@ -0,0 +1,25 @@ +{ + "version": 8, + "sources": { + "geojson": { + "type": "geojson", + "data": { + "type": "Point", + "coordinates": [ + 0, + 0 + ] + } + } + }, + "layers": [ + { + "id": "symbol", + "type": "symbol", + "source": "geojson", + "layout": { + "icon-image": "test-icon" + } + } + ] +} diff --git a/test/fixtures/map/add_icon/expected.png b/test/fixtures/map/add_icon/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..0297f7c0cea29e618914cf41066a65b2e7a50af2 GIT binary patch literal 1741 zcmcJP`#;kQ7{|XObk@-l3Av;?t#Im8;^cm$A(y$N?PyF$#Y~n#Mi#!Mw4EZ5p~ljJZ@mn)P#4r(bb#m@|%JnQNI};L-KW&#Z4`dt_|{JMOk7 zxTqJo2Cv;1F)D#s)*SSHH`&wo5LuLKlP`ky+V#XXS?c7Xwnkdv^=4ef0o0pEP@a6yrd7`s>Y&+%26LcFh)xmVw zVYco&ByPyS9tM+;*lb57R^JJ)d{ehB#-P}=TWJTxKz#(;QDb}pWLkMe4$s|v6an>h!%O>!#51Ut4RSL( zy?qBa@kW9SIL)!7OcZx1zzw;nYpWQz7Xv?awp^Z`)ogvT6 z$yj=;7U8W`($`qK4le^~6ojN^F!73e|D-TBQ9?K+Axp{ElBdbt^&$RotdiWlRfj>5 z*VHa1dV?Ynit!NIIK|a`LRYuHg^3Gli2vaF8oKiaZXo9g|4>CtS+QvVU`X*2H03Td zl;qAqJsl40->8au|L&UUCEYLOg@vEsC1N9f*{TKZY{~=6YMC7aFciKR^9?#}#1o}| zmN(VZ=mZANNH?Q@M9|UkrBtckx_htvZ5Eo2G4p^q|_yGEvl z5o!NA+uIqz5f=V5T0W839SE-*gi5GEmq`N+?tB?it!G!@MY7#1%<=6$aNpO_46Gbp zG#G5v@g_W8NOIm5e&aaFLr|<$(K}%TqZ9O8vJ;Cw_QD&|xf69Ps?2Kk1k&n_Bg)*4{;%t}?)+mT)TZ=NsyD2THo?kMs z4}#-W+(o~m1VvV=b+xGXMjhN7KYQ7$)O5ZKvL_@5)$V_Obutk6{CJ?M?=$P|+ld9O zGH_*s@P>{3iRFg^eCxXYPx~~O>y0rs)T*?M)lNkHNV3JbCSgu~11i_oscki^NjBY< z=mNT{8yENX>j%uxp^UaWkI_(Qgw2$3X6nll2*)7T^y^XPq*q5rhp9ZlE&`1i{DU2f zovux1qsFG88oW@Bez8D6t1>cLjI9yu)`mbJ*3@1$(IZutidC&`$B|a?2ICwwA66~A!1gq%uB)}#$U>$Nn~>SQ%U$E+kHBS;wAY?fYr)! zrm|P6Sm1KGPkVa2TRAUe`Wgi%$8dNIYeu22PIDASYxllunVB6+ajX}G&I`EZ1y0xawph_73{YuKg#0C7JA;Q#;t literal 0 HcmV?d00001 diff --git a/test/fixtures/map/remove_icon/expected.png b/test/fixtures/map/remove_icon/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..b97b635a21a6c110f175392848101bf2826f7d04 GIT binary patch literal 355 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%U;1OBOz`%C|gc+x5^GO3$ yhhE&XXd(aT1;n0Gw{%^B6766$e7*sGb+AuKMybb0A1%jumpUXO@geCxFDi-Ge literal 0 HcmV?d00001 diff --git a/test/map/map.cpp b/test/map/map.cpp index 043729635..12d4ff2bc 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -343,3 +345,34 @@ TEST(Map, Classes) { EXPECT_TRUE(map.getClasses().empty()); EXPECT_FALSE(map.getTransitionOptions().duration); } + +TEST(Map, AddImage) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + auto decoded1 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); + auto decoded2 = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); + auto image1 = std::make_unique(std::move(decoded1), 1.0); + auto image2 = std::make_unique(std::move(decoded2), 1.0); + + // No-op. + map.addImage("test-icon", std::move(image1)); + + map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); + map.addImage("test-icon", std::move(image2)); + test::checkImage("test/fixtures/map/add_icon", test::render(map)); +} + +TEST(Map, RemoveImage) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + auto decoded = decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")); + auto image = std::make_unique(std::move(decoded), 1.0); + + map.setStyleJSON(util::read_file("test/fixtures/api/icon_style.json")); + map.addImage("test-icon", std::move(image)); + map.removeImage("test-icon"); + test::checkImage("test/fixtures/map/remove_icon", test::render(map)); +} +