1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837 |
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #include "../include/Config.h"
- #include "../include/JsonCommander.h"
- #include "../include/Notifications.h"
- #include "ChannelControlsMock.h"
- #include "FileManagerMock.h"
- #include "QueueMock.h"
- namespace {
- /* Version tests */
- TEST(testVersion, PositiveAllEqual) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- Json::Value message;
- message["major"] = 0;
- message["minor"] = 1;
- JsonCommander::Response response = jsonCommander.testVersion(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
- EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
- }
- TEST(testVersion, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- Json::Value message;
- message["major"] = jsonCommander.protocolMajorVersion;
- message["minor"] = jsonCommander.protocolMinorVersion - 1;
- JsonCommander::Response response = jsonCommander.testVersion(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
- EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
- }
- TEST(testVersion, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- Json::Value message;
- message["major"] = "def";
- message["minor"] = "abc";
- JsonCommander::Response response = jsonCommander.testVersion(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
- EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
- }
- TEST(testVersion, NotEqualMajorNumber) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- Json::Value message;
- message["major"] = jsonCommander.protocolMajorVersion + 1;
- message["minor"] = jsonCommander.protocolMinorVersion;
- JsonCommander::Response response = jsonCommander.testVersion(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
- EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
- }
- TEST(testVersion, BiggerMinorNumber) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- Json::Value message;
- message["major"] = jsonCommander.protocolMajorVersion;
- message["minor"] = jsonCommander.protocolMinorVersion + 1;
- JsonCommander::Response response = jsonCommander.testVersion(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
- EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
- }
- /* Status tests */
- TEST(Status, Ok) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "status";
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["response"].asString(), "ok");
- }
- TEST(Status, Downloading) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "status";
- Json::Value message;
- message["command"] = command;
- ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["response"].asString(), "download running");
- }
- TEST(Status, Uploading) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "status";
- Json::Value message;
- message["command"] = command;
- ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["response"].asString(), "upload running");
- }
- TEST(Status, UploadingAndDownloading) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "status";
- Json::Value message;
- message["command"] = command;
- ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["response"].asString(), "download and upload running");
- }
- /* Close tests */
- TEST(Close, Close) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "close";
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["response"].asString(), "bye");
- }
- /* Put tests */
- TEST(Put, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "put";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- message["size"] = 1337;
- message["chunks"] = 1;
- ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Put, Negative) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "put";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- message["size"] = 1337;
- message["chunks"] = 1;
- ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_TRUE(response.json["error"].asString().length() > 0);
- }
- /* Putdata tests */
- TEST(Putdata, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- /* start with put */
- std::string command = "put";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- message["size"] = 1337;
- const int chunks = 3;
- message["chunks"] = chunks;
- ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* putdata */
- command = "putdata";
- ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
- for (int remaining = chunks - 1; remaining >= 0; remaining--) {
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["data"] = "MTMzNw==";
- message["remaining"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["received"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- }
- TEST(Putdata, Cancel) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- /* start with put */
- std::string command = "put";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- message["size"] = 1337;
- const int chunks = 3;
- message["chunks"] = chunks;
- ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* putdata */
- command = "putdata";
- ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
- int remaining = chunks - 1;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["data"] = "MTMzNw==";
- message["remaining"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["received"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- // cancel transfer
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["data"] = "MTMzNw==";
- message["remaining"] = --remaining;
- message["cancel"] = true;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["received"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Putdata, WrongRemaining) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- /* start with put */
- std::string command = "put";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- message["size"] = 1337;
- const int chunks = 3;
- message["chunks"] = chunks;
- ON_CALL(fileManager, openPutFile(testing::_)).WillByDefault(testing::Return(true));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* putdata */
- command = "putdata";
- ON_CALL(fileManager, isUploading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getPutBaseFileName()).WillByDefault(testing::Return(filename));
- int remaining = chunks - 1;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["data"] = "MTMzNw==";
- message["remaining"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["received"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["error"].asString(), "");
- message = Json::Value();
- // skip remaining=1 and provoke an error
- remaining = 0;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["data"] = "MTMzNw==";
- message["remaining"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["received"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_TRUE(response.json["error"].asString().length() > 0);
- }
- /* Get tests */
- TEST(Get, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "get";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- const int chunks = 3;
- EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["chunks"].asInt(), chunks);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Get, Negative) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "get";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(false, -1)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["chunks"].asInt(), -1);
- EXPECT_TRUE(response.json["error"].asString().length() > 0);
- }
- /* Getdata tests */
- TEST(Getdata, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- std::string command = "get";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- const int chunks = 3;
- EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["chunks"].asInt(), chunks);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* getdata */
- command = "getdata";
- ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
- std::vector<char> data;
- data.push_back('1');
- data.push_back('3');
- data.push_back('3');
- data.push_back('7');
- ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
- for (int remaining = chunks - 1; remaining >= 0; remaining--) {
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["chunk"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- }
- TEST(Getdata, Cancle) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- std::string command = "get";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- const int chunks = 3;
- EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["chunks"].asInt(), chunks);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* getdata */
- command = "getdata";
- ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
- std::vector<char> data;
- data.push_back('1');
- data.push_back('3');
- data.push_back('3');
- data.push_back('7');
- ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
- int remaining = chunks - 1;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["chunk"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
- EXPECT_EQ(response.json["error"].asString(), "");
- // set cancel to true
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["chunk"] = --remaining;
- message["cancel"] = true;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["data"].asString(), "");
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Getdata, WrongChunk) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- std::string command = "get";
- const std::string filename = "cool.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = filename;
- const int chunks = 3;
- EXPECT_CALL(fileManager, openGetFile(testing::_)).WillOnce(testing::Return(std::pair<bool, int>(true, chunks)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["chunks"].asInt(), chunks);
- EXPECT_EQ(response.json["error"].asString(), "");
- /* getdata */
- command = "getdata";
- ON_CALL(fileManager, isDownloading()).WillByDefault(testing::Return(true));
- ON_CALL(fileManager, getGetBaseFileName()).WillByDefault(testing::Return(filename));
- std::vector<char> data;
- data.push_back('1');
- data.push_back('3');
- data.push_back('3');
- data.push_back('7');
- ON_CALL(fileManager, readGet()).WillByDefault(testing::Return(data));
- int remaining = chunks - 1;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["chunk"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["data"].asString(), "MTMzNw==");
- EXPECT_EQ(response.json["error"].asString(), "");
- // skip chunk=0
- remaining = 0;
- message = Json::Value();
- message["command"] = command;
- message["file"] = filename;
- message["chunk"] = remaining;
- message["cancel"] = false;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining);
- EXPECT_EQ(response.json["file"].asString(), filename);
- EXPECT_EQ(response.json["data"].asString(), "");
- EXPECT_TRUE(response.json["error"].asString().length() > 0);
- }
- /* List tests */
- TEST(List, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "list";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(1));
- EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(5));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), 1);
- EXPECT_EQ(response.json["items"].asInt(), 5);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(List, Negative) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "list";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(-1));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), -1);
- EXPECT_EQ(response.json["items"].asInt(), -1);
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(List, EmptyList) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "list";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, openList()).WillOnce(testing::Return(0));
- EXPECT_CALL(fileManager, getListSize()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), 0);
- EXPECT_EQ(response.json["items"].asInt(), 0);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- /* Listdata tests */
- void fillExampleFileList(std::vector<std::string> (&chunk)[3]) {
- chunk[0].push_back("file01.txt");
- chunk[0].push_back("bumdibumps");
- chunk[0].push_back("1");
- chunk[0].push_back("Ich habe Hunger.txt");
- chunk[0].push_back("answerIs42");
- chunk[0].push_back("123456789456115811");
- chunk[0].push_back("kek");
- chunk[1].push_back("1337");
- chunk[1].push_back("cats.png");
- chunk[1].push_back("more_cats.png");
- chunk[1].push_back("ugly dog.tiff");
- chunk[1].push_back("hello.txt");
- chunk[1].push_back("bye.exe");
- chunk[1].push_back("poster.pdf");
- chunk[2].push_back("headbang.gif");
- chunk[2].push_back("feelsbad.jpg");
- chunk[2].push_back("hack.s");
- chunk[2].push_back("SodiumChloride");
- chunk[2].push_back("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst"
- "uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN"
- "OPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
- }
- TEST(Listdata, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "listdata";
- const int chunks = 3;
- std::vector<std::string> chunk[chunks];
- fillExampleFileList(chunk);
- int remaining = chunks - 1;
- for (int k = 0; k < chunks; k++) {
- Json::Value message;
- message["command"] = command;
- message["chunk"] = remaining;
- message["cancel"] = false;
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
- EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[k]));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
- EXPECT_TRUE(response.json["names"].isArray());
- Json::Value array = response.json["names"];
- EXPECT_EQ(array.size(), chunk[k].size());
- for (int i = 0; i < 3; i++) {
- EXPECT_EQ(array[i].asString(), chunk[k][i]);
- }
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- }
- TEST(Listdata, Cancel) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "listdata";
- const int chunks = 3;
- std::vector<std::string> chunk[chunks];
- fillExampleFileList(chunk);
- int remaining = chunks - 1;
- Json::Value message;
- message["command"] = command;
- message["chunk"] = remaining;
- message["cancel"] = false;
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
- EXPECT_CALL(fileManager, getNextChunkFromList()).WillOnce(testing::Return(chunk[0]));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
- EXPECT_TRUE(response.json["names"].isArray());
- Json::Value array = response.json["names"];
- EXPECT_EQ(array.size(), chunk[0].size());
- for (int i = 0; i < 3; i++) {
- EXPECT_EQ(array[i].asString(), chunk[0][i]);
- }
- EXPECT_EQ(response.json["error"].asString(), "");
- message = Json::Value();
- message["command"] = command;
- message["chunk"] = remaining;
- message["cancel"] = true;
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining + 1));
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), remaining--);
- EXPECT_TRUE(response.json["names"].isArray());
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Listdata, WrongChunkNumber) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "listdata";
- const int chunks = 3;
- int remaining = chunks - 1;
- Json::Value message;
- message["command"] = command;
- message["chunk"] = remaining;
- message["cancel"] = false;
- // return smaller remaining
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(remaining));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["names"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Listdata, NoChunksToBeSend) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "listdata";
- const int chunks = 0;
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 1;
- message["cancel"] = false;
- // return smaller remaining
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["names"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Listdata, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "listdata";
- const int chunks = 3;
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 1;
- // return smaller remaining
- EXPECT_CALL(fileManager, getRemainingListChunks()).WillOnce(testing::Return(chunks));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["names"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Head, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "head";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- std::vector<char> bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
- const std::string bytesAsString = "YWJjZGVmZ2g=";
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_error)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_EQ(response.json["data"].asString(), bytesAsString);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Head, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "head";
- const int file = 3641;
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "");
- EXPECT_EQ(response.json["data"].asString(), "");
- EXPECT_NE(response.json["error"].asString(), "");
- }
- TEST(Head, NoSuchFile) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "head";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- std::vector<char> bytes;
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_such_file)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_EQ(response.json["data"].asString(), "");
- EXPECT_NE(response.json["error"].asString(), "");
- }
- TEST(Head, FileTooSmall) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "head";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- std::vector<char> bytes;
- EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_))
- .Times(2)
- .WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_EQ(response.json["data"].asString(), "");
- EXPECT_NE(response.json["error"].asString(), "");
- }
- TEST(Deleteme, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- // need to set currentUser in jsonCommander via calling checkLogin
- Json::Value login;
- login["login"] = true;
- login["user"] = "positive";
- login["pass"] = "positive";
- login["cancel"] = false;
- JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
- EXPECT_TRUE(loginRes.json["accept"].asBool());
- EXPECT_EQ(loginRes.json["error"].asString(), "");
- // now the actual test
- const std::string command = "deleteme";
- Json::Value message;
- message["command"] = command;
- message["pass"] = "positive";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Deleteme, Negative) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- // need to set currentUser in jsonCommander via calling checkLogin
- Json::Value login;
- login["login"] = true;
- login["user"] = "positive";
- login["pass"] = "positive";
- login["cancel"] = false;
- JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
- EXPECT_TRUE(loginRes.json["accept"].asBool());
- EXPECT_EQ(loginRes.json["error"].asString(), "");
- // now the actual test
- const std::string command = "deleteme";
- Json::Value message;
- message["command"] = command;
- message["pass"] = "negative";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_EQ(response.action, JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_NE(response.json["error"].asString(), "");
- }
- TEST(Deleteme, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- // need to set currentUser in jsonCommander via calling checkLogin
- Json::Value login;
- login["login"] = true;
- login["user"] = "positive";
- login["pass"] = "positive";
- login["cancel"] = false;
- JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
- EXPECT_TRUE(loginRes.json["accept"].asBool());
- EXPECT_EQ(loginRes.json["error"].asString(), "");
- // now the actual test
- const std::string command = "deleteme";
- Json::Value message;
- message["command"] = command;
- message["pass"] = 123;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_NE(response.json["error"].asString(), "");
- }
- TEST(DeleteFile, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "deletefile";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_error));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(DeleteFile, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "deletefile";
- const int file = 3641;
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["file"].asString(), "");
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(DeleteFile, FileDoesNotExist) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "deletefile";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_such_file));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(DeleteFile, DisabledInConfig) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "deletefile";
- const std::string file = "asdf.txt";
- Json::Value message;
- message["command"] = command;
- message["file"] = file;
- EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::not_allowed));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_EQ(response.json["file"].asString(), file);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(ExtendedStatus, NoUploadOrDownload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["transfersclientserver"].isNull());
- EXPECT_TRUE(response.json["transfersserverserver"].isNull());
- }
- TEST(ExtendedStatus, ClientServerDownload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(true));
- EXPECT_CALL(fileManager, getGetBaseFileName()).WillOnce(testing::Return("asdf"));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
- EXPECT_FALSE(response.json["transfersclientserver"][0]["upload"].asBool());
- EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
- EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
- }
- TEST(ExtendedStatus, ClientServerUpload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(true));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, getPutBaseFileName()).WillOnce(testing::Return("asdf"));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
- EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
- EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
- EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
- }
- TEST(ExtendedStatus, ClientServerDonwloadAndUpload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(true));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(true));
- EXPECT_CALL(fileManager, getGetBaseFileName()).WillOnce(testing::Return("asdfGet"));
- EXPECT_CALL(fileManager, getPutBaseFileName()).WillOnce(testing::Return("asdfPut"));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 2);
- EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
- EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdfPut");
- EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
- EXPECT_FALSE(response.json["transfersclientserver"][1]["upload"].asBool());
- EXPECT_EQ(response.json["transfersclientserver"][1]["file"].asString(), "asdfGet");
- EXPECT_TRUE(response.json["transfersclientserver"][1]["progress"].isInt());
- }
- TEST(ExtendedStatus, ServerServerDownload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- Queue::fileName = "a.txt";
- Config::storage.clear();
- Config::storage.insert(std::pair<std::string, std::string>("passiveMode", "true"));
- Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(true));
- EXPECT_CALL(channelControls, getProgress()).WillOnce(testing::Return(std::pair<int, int>(1, 2)));
- EXPECT_CALL(channelControls, getTransferStart()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
- EXPECT_EQ(response.json["transfersserverserver"].size(), 1);
- EXPECT_EQ(response.json["transfersserverserver"][0]["type"].asString(), "download");
- EXPECT_EQ(response.json["transfersserverserver"][0]["file"].asString(), "a.txt");
- EXPECT_EQ(response.json["transfersserverserver"][0]["progress"].asInt(), 50);
- EXPECT_TRUE(response.json["transfersserverserver"][0]["speed"].isDouble());
- EXPECT_EQ(response.json["transfersserverserver"][0]["method"].asString(), "m");
- }
- TEST(ExtendedStatus, ServerServerUpload) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- Queue::fileName = "a.txt";
- Config::storage.clear();
- Config::storage.insert(std::pair<std::string, std::string>("passiveMode", "false"));
- Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(true));
- EXPECT_CALL(channelControls, getProgress()).WillOnce(testing::Return(std::pair<int, int>(1, 2)));
- EXPECT_CALL(channelControls, getTransferStart()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
- EXPECT_EQ(response.json["transfersserverserver"].size(), 1);
- EXPECT_EQ(response.json["transfersserverserver"][0]["type"].asString(), "upload");
- EXPECT_EQ(response.json["transfersserverserver"][0]["file"].asString(), "a.txt");
- EXPECT_EQ(response.json["transfersserverserver"][0]["progress"].asInt(), 50);
- EXPECT_TRUE(response.json["transfersserverserver"][0]["speed"].isDouble());
- EXPECT_EQ(response.json["transfersserverserver"][0]["method"].asString(), "m");
- }
- TEST(ExtendedStatus, QueueNotEmpty) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- ChannelControlsMock channelControls;
- Queue::channel = &channelControls;
- Queue::queue.clear();
- Queue::queue.push_back("a");
- Queue::queue.push_back("b");
- Config::storage.clear();
- Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
- const std::string command = "extendedstatus";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
- EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
- EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
- EXPECT_EQ(response.json["transfersserverserver"].size(), 2);
- EXPECT_EQ(response.json["transfersserverserver"][0]["type"], "queued");
- EXPECT_EQ(response.json["transfersserverserver"][0]["file"], "a");
- EXPECT_EQ(response.json["transfersserverserver"][0]["progress"], 0);
- EXPECT_EQ(response.json["transfersserverserver"][0]["speed"], 0);
- EXPECT_EQ(response.json["transfersserverserver"][0]["method"], "m");
- EXPECT_EQ(response.json["transfersserverserver"][1]["type"], "queued");
- EXPECT_EQ(response.json["transfersserverserver"][1]["file"], "b");
- EXPECT_EQ(response.json["transfersserverserver"][1]["progress"], 0);
- EXPECT_EQ(response.json["transfersserverserver"][1]["speed"], 0);
- EXPECT_EQ(response.json["transfersserverserver"][1]["method"], "m");
- }
- TEST(Notifications, NoMessage) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "notifications";
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["messages"].isNull());
- }
- TEST(Notifications, OneMessage) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "notifications";
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- Notifications::newNotification("asdf");
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["messages"].isArray());
- EXPECT_EQ(response.json["messages"][0], "asdf");
- // cleaning up
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- }
- TEST(Notifications, OneMessageMultipleTimesCalled) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "notifications";
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- Notifications::newNotification("asdf");
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["messages"].isArray());
- EXPECT_EQ(response.json["messages"][0], "asdf");
- // make suhre that timestamp from message is older
- Notifications::messages.at(0).first--;
- response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["messages"].isNull());
- // cleaning up
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- }
- TEST(Notifications, TwoMessages) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "notifications";
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- Notifications::newNotification("asdf");
- Notifications::newNotification("qwer");
- Json::Value message;
- message["command"] = command;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["error"].asString(), "");
- EXPECT_TRUE(response.json["messages"].isArray());
- EXPECT_EQ(response.json["messages"][0], "asdf");
- EXPECT_EQ(response.json["messages"][1], "qwer");
- // cleaning up
- Notifications::messages.clear();
- Notifications::userTimeStamps.clear();
- }
- TEST(ExtendedList, positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlist";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
- EXPECT_CALL(fileManager, openExtendedList()).WillOnce(testing::Return(1));
- EXPECT_CALL(fileManager, getExtendedListSize()).WillOnce(testing::Return(5));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), 1);
- EXPECT_EQ(response.json["items"].asInt(), 5);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(ExtendedList, negative) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlist";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
- EXPECT_CALL(fileManager, openExtendedList()).WillOnce(testing::Return(-1));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), -1);
- EXPECT_EQ(response.json["items"].asInt(), -1);
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(ExtendedList, EmptyList) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlist";
- Json::Value message;
- message["command"] = command;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
- EXPECT_CALL(fileManager, openExtendedList()).WillOnce(testing::Return(0));
- EXPECT_CALL(fileManager, getExtendedListSize()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["chunks"].asInt(), 0);
- EXPECT_EQ(response.json["items"].asInt(), 0);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(ExtendedListData, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlistdata";
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 0;
- message["cancel"] = false;
- std::vector<std::tuple<std::string, std::string, double>> chunks;
- std::tuple<std::string, std::string, double> chunk = std::tuple("asdf", "asdfghjkasdfghjkasdfghjkasdfghjk", 41.2);
- chunks.push_back(chunk);
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
- EXPECT_CALL(fileManager, getNextChunkFromExtendedList()).WillOnce(testing::Return(chunks));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), 0);
- EXPECT_TRUE(response.json["files"].isArray());
- EXPECT_EQ(response.json["files"].size(), 1);
- EXPECT_EQ(response.json["files"][0]["name"].asString(), "asdf");
- EXPECT_NE(response.json["files"][0]["head"].asString(), "");
- EXPECT_EQ(response.json["files"][0]["size"].asDouble(), 41.2);
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(ExtendedListData, Cancel) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlistdata";
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 0;
- message["cancel"] = true;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
- EXPECT_CALL(fileManager, cancelExtendedList());
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), 0);
- EXPECT_TRUE(response.json["files"].isArray());
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(ExtendedListData, WrongChunkNumber) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlistdata";
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 1;
- message["cancel"] = false;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(1));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["files"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(ExtendedListData, NoChunksToBeSend) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlistdata";
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 1;
- message["cancel"] = false;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["files"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(ExtendedListData, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "extendedlistdata";
- Json::Value message;
- message["command"] = command;
- message["chunk"] = 5;
- EXPECT_CALL(fileManager, getRemainingExtendedListChunks()).WillOnce(testing::Return(0));
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["cancel"].asBool());
- EXPECT_EQ(response.json["remaining"].asInt(), -1);
- EXPECT_TRUE(response.json["files"].isArray());
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Queue, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "queue";
- Json::Value message;
- message["command"] = command;
- message["file"] = 5;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "");
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Queue, PushToQueueFailed) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "queue";
- Json::Value message;
- message["command"] = command;
- message["file"] = "negative";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "negative");
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Queue, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "queue";
- Json::Value message;
- message["command"] = command;
- message["file"] = "positive";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "positive");
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- TEST(Dequeue, InvalidRequest) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "dequeue";
- Json::Value message;
- message["command"] = command;
- message["file"] = 5;
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "");
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Dequeue, QueueRemoveFailed) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "dequeue";
- Json::Value message;
- message["command"] = command;
- message["file"] = "negative";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_FALSE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "negative");
- EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
- }
- TEST(Dequeue, Positive) {
- FileManagerMock fileManager;
- JsonCommander jsonCommander(fileManager);
- const std::string command = "dequeue";
- Json::Value message;
- message["command"] = command;
- message["file"] = "positive";
- JsonCommander::Response response = jsonCommander.execute(message);
- EXPECT_TRUE(response.action == JsonCommander::Action::send);
- EXPECT_EQ(response.json["command"].asString(), command);
- EXPECT_TRUE(response.json["accept"].asBool());
- EXPECT_EQ(response.json["file"].asString(), "positive");
- EXPECT_EQ(response.json["error"].asString(), "");
- }
- } // namespace
|