diff --git a/gui/include/Parsing/ServerParser.hpp b/gui/include/Parsing/ServerParser.hpp index d319f746..96adc34f 100644 --- a/gui/include/Parsing/ServerParser.hpp +++ b/gui/include/Parsing/ServerParser.hpp @@ -53,7 +53,8 @@ class Gui::ServerParser { enum ParseType { INT, STRING, - HASHTAG + MESSAGE, + LIST_INT }; private: @@ -67,25 +68,27 @@ class Gui::ServerParser { {"msz", std::vector{INT, INT}}, {"bct", std::vector{INT, INT, INT, INT, INT, INT, INT, INT, INT}}, {"tna", std::vector{STRING}}, - {"pnw", std::vector{HASHTAG, INT, INT, INT, INT, STRING}}, - {"ppo", std::vector{HASHTAG, INT, INT, INT}}, - {"plv", std::vector{HASHTAG, INT}}, - {"pin", std::vector{HASHTAG, INT, INT, INT, INT, INT, INT, INT, INT, INT}}, - {"pex", std::vector{HASHTAG}}, - {"pfk", std::vector{HASHTAG}}, - {"pdr", std::vector{HASHTAG, INT}}, - {"pgt", std::vector{HASHTAG, INT}}, - {"pdi", std::vector{HASHTAG}}, - {"enw", std::vector{HASHTAG, HASHTAG, INT, INT}}, - {"ebo", std::vector{HASHTAG}}, - {"edi", std::vector{HASHTAG}}, + {"pnw", std::vector{INT, INT, INT, INT, INT, STRING}}, + {"ppo", std::vector{INT, INT, INT, INT}}, + {"plv", std::vector{INT, INT}}, + {"pin", std::vector{INT, INT, INT, INT, INT, INT, INT, INT, INT, INT}}, + {"pex", std::vector{INT}}, + {"pbc", std::vector{INT, MESSAGE}}, + {"pic", std::vector{INT, INT, INT, LIST_INT}}, + {"pie", std::vector{INT, INT, INT}}, + {"pfk", std::vector{INT}}, + {"pdr", std::vector{INT, INT}}, + {"pgt", std::vector{INT, INT}}, + {"pdi", std::vector{INT}}, + {"enw", std::vector{INT, INT, INT, INT}}, + {"ebo", std::vector{INT}}, + {"edi", std::vector{INT}}, {"sgt", std::vector{INT}}, {"sst", std::vector{INT}}, {"seg", std::vector{STRING}}, + {"smg", std::vector{MESSAGE}}, {"suc", std::vector{}}, {"sbp", std::vector{}} - // TODO : pbc, pic, pie, smg - // #15 (https://github.com/FppEpitech/Zappy/issues/15)) }; /** @@ -116,11 +119,22 @@ class Gui::ServerParser { std::vector parseString(std::istringstream& stream, std::vector arguments); /** - * @brief Parse an hashtag in the command stream. + * @brief Parse a message in the command stream. * * @param stream Stream to parse. * @param arguments List of arguments parsed. + * @param commandName Name of the server command. * @return std::vector - arguments parsed */ - std::vector parseHashtag(std::istringstream& stream, std::vector arguments, std::string commandName); + std::vector parseMessage(std::istringstream& stream, std::vector arguments, std::string commandName); + + /** + * @brief Parse a list of int in the command stream. + * + * @param stream Stream to parse. + * @param arguments List of arguments parsed. + * @param commandName Name of the server command. + * @return std::vector - arguments parsed + */ + std::vector parseListInt(std::istringstream& stream, std::vector arguments, std::string commandName); }; diff --git a/gui/src/Parsing/ParseCommandLine.cpp b/gui/src/Parsing/ParseCommandLine.cpp index b7309e35..7742af48 100644 --- a/gui/src/Parsing/ParseCommandLine.cpp +++ b/gui/src/Parsing/ParseCommandLine.cpp @@ -38,10 +38,8 @@ void Gui::ParseCommandLine::parseFlags(int argc, char **argv) } else throw Errors::ParseCommandLineException(GUI_USAGE); } - if (!isPort || !isHostname) { - std::cout << isPort << isHostname << std::endl; + if (!isPort || !isHostname) throw Errors::ParseCommandLineException(GUI_USAGE); - } } int Gui::ParseCommandLine::getPort(void) diff --git a/gui/src/Parsing/ServerParser.cpp b/gui/src/Parsing/ServerParser.cpp index 68fffc7d..cffc1f9d 100644 --- a/gui/src/Parsing/ServerParser.cpp +++ b/gui/src/Parsing/ServerParser.cpp @@ -42,10 +42,13 @@ std::vector Gui::ServerParser::parseCommand(const std::string& comm arguments = parseString(stream, arguments); break; } - case Gui::ServerParser::ParseType::HASHTAG: + case Gui::ServerParser::ParseType::MESSAGE: { - arguments = parseHashtag(stream, arguments, commandName); - break; + return parseMessage(stream, arguments, commandName); + } + case Gui::ServerParser::ParseType::LIST_INT: + { + return parseListInt(stream, arguments, commandName); } default: break; @@ -75,14 +78,32 @@ std::vector Gui::ServerParser::parseString(std::istringstream& stre return arguments; } -std::vector Gui::ServerParser::parseHashtag(std::istringstream& stream, std::vector arguments, std::string commandName) +std::vector Gui::ServerParser::parseMessage(std::istringstream& stream, std::vector arguments, std::string commandName) { - char hashtag; - stream >> hashtag; - if (hashtag != '#') + if (stream.fail()) + throw Errors::ServerParserException("Wrong parameters for '" + commandName + "' command."); + + std::string start; + stream >> start; + if (stream.fail()) throw Errors::ServerParserException("Wrong parameters for '" + commandName + "' command."); - int nb; - stream >> nb; - arguments.push_back(std::to_string(nb)); + std::string end; + std::getline(stream, end, '\0'); + arguments.push_back(start + end); return arguments; } + +std::vector Gui::ServerParser::parseListInt(std::istringstream& stream, std::vector arguments, std::string commandName) +{ + if (stream.fail()) + throw Errors::ServerParserException("Wrong parameters for '" + commandName + "' command."); + while (1) { + int player; + stream >> player; + if (stream.fail()) + throw Errors::ServerParserException("Wrong parameters for '" + commandName + "' command."); + arguments.push_back(std::to_string(player)); + if((stream.eof())) + return arguments; + } +} diff --git a/gui/tests/Parsing/TestParser.cpp b/gui/tests/Parsing/TestParser.cpp index 847e8f6c..d338393b 100644 --- a/gui/tests/Parsing/TestParser.cpp +++ b/gui/tests/Parsing/TestParser.cpp @@ -146,7 +146,7 @@ Test(ParseServer, correct_pnw_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pnw #1 2 3 4 5 team"); + test = parser.parse("pnw 1 2 3 4 5 team"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -162,33 +162,20 @@ Test(ParseServer, pnw_too_long, .timeout = 5) std::string test; try { - parser.parse("pnw #1 2 3 4 5 team team2"); + parser.parse("pnw 1 2 3 4 5 team team2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pnw' command."); } -Test(ParseServer, pnw_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pnw 1 2 3 4 5 team"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pnw' command."); -} - Test(ParseServer, pnw_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pnw #1 2 wrong 4 5 team"); + parser.parse("pnw 1 2 wrong 4 5 team"); } catch (const std::exception &error) { test = error.what(); } @@ -202,7 +189,7 @@ Test(ParseServer, correct_ppo_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("ppo #1 2 3 4"); + test = parser.parse("ppo 1 2 3 4"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -216,33 +203,20 @@ Test(ParseServer, ppo_too_long, .timeout = 5) std::string test; try { - parser.parse("ppo #1 2 3 4 5"); + parser.parse("ppo 1 2 3 4 5"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'ppo' command."); } -Test(ParseServer, ppo_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("ppo 1 2 3 4"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'ppo' command."); -} - Test(ParseServer, ppo_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("ppo #1 2 wrong 4"); + parser.parse("ppo 1 2 wrong 4"); } catch (const std::exception &error) { test = error.what(); } @@ -256,7 +230,7 @@ Test(ParseServer, correct_plv_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("plv #1 2"); + test = parser.parse("plv 1 2"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -268,33 +242,20 @@ Test(ParseServer, plv_too_long, .timeout = 5) std::string test; try { - parser.parse("plv #1 2 3"); + parser.parse("plv 1 2 3"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'plv' command."); } -Test(ParseServer, plv_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("plv 1 2"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'plv' command."); -} - Test(ParseServer, plv_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("plv #1 wrong"); + parser.parse("plv 1 wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -308,7 +269,7 @@ Test(ParseServer, correct_pin_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pin #1 2 3 0 1 2 3 4 5 6"); + test = parser.parse("pin 1 2 3 0 1 2 3 4 5 6"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -323,33 +284,20 @@ Test(ParseServer, pin_too_long, .timeout = 5) std::string test; try { - parser.parse("pin #1 2 3 0 1 2 3 4 5 6 7"); + parser.parse("pin 1 2 3 0 1 2 3 4 5 6 7"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pin' command."); } -Test(ParseServer, pin_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pin 1 2 3 0 1 2 3 4 5 6"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pin' command."); -} - Test(ParseServer, pin_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pin #1 2 3 0 1 2 wrong 4 5 6"); + parser.parse("pin 1 2 3 0 1 2 wrong 4 5 6"); } catch (const std::exception &error) { test = error.what(); } @@ -363,7 +311,7 @@ Test(ParseServer, correct_pex_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pex #1"); + test = parser.parse("pex 1"); cr_assert_eq(test[0], "1"); } @@ -374,33 +322,20 @@ Test(ParseServer, pex_too_long, .timeout = 5) std::string test; try { - parser.parse("pex #1 2"); + parser.parse("pex 1 2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pex' command."); } -Test(ParseServer, pex_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pex 1"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pex' command."); -} - Test(ParseServer, pex_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pex #wrong"); + parser.parse("pex wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -414,7 +349,7 @@ Test(ParseServer, correct_pfk_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pfk #1"); + test = parser.parse("pfk 1"); cr_assert_eq(test[0], "1"); } @@ -425,33 +360,20 @@ Test(ParseServer, pfk_too_long, .timeout = 5) std::string test; try { - parser.parse("pfk #1 2"); + parser.parse("pfk 1 2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pfk' command."); } -Test(ParseServer, pfk_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pfk 1"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pfk' command."); -} - Test(ParseServer, pfk_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pfk #wrong"); + parser.parse("pfk wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -465,7 +387,7 @@ Test(ParseServer, correct_pdr_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pdr #1 2"); + test = parser.parse("pdr 1 2"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -477,33 +399,20 @@ Test(ParseServer, pdr_too_long, .timeout = 5) std::string test; try { - parser.parse("pdr #1 2 3"); + parser.parse("pdr 1 2 3"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pdr' command."); } -Test(ParseServer, pdr_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pdr 1 2"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pdr' command."); -} - Test(ParseServer, pdr_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pdr #1 a"); + parser.parse("pdr 1 a"); } catch (const std::exception &error) { test = error.what(); } @@ -517,7 +426,7 @@ Test(ParseServer, correct_pgt_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pgt #1 2"); + test = parser.parse("pgt 1 2"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -529,33 +438,20 @@ Test(ParseServer, pgt_too_long, .timeout = 5) std::string test; try { - parser.parse("pgt #1 2 3"); + parser.parse("pgt 1 2 3"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pgt' command."); } -Test(ParseServer, pgt_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pgt 1 2"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pgt' command."); -} - Test(ParseServer, pgt_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pgt #1 a"); + parser.parse("pgt 1 a"); } catch (const std::exception &error) { test = error.what(); } @@ -569,7 +465,7 @@ Test(ParseServer, correct_pdi_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("pdi #1"); + test = parser.parse("pdi 1"); cr_assert_eq(test[0], "1"); } @@ -580,33 +476,20 @@ Test(ParseServer, pdi_too_long, .timeout = 5) std::string test; try { - parser.parse("pdi #1 2"); + parser.parse("pdi 1 2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'pdi' command."); } -Test(ParseServer, pdi_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("pdi 1"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pdi' command."); -} - Test(ParseServer, pdi_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("pdi #wrong"); + parser.parse("pdi wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -620,7 +503,7 @@ Test(ParseServer, correct_enw_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("enw #1 #2 3 4"); + test = parser.parse("enw 1 2 3 4"); cr_assert_eq(test[0], "1"); cr_assert_eq(test[1], "2"); @@ -634,46 +517,20 @@ Test(ParseServer, enw_too_long, .timeout = 5) std::string test; try { - parser.parse("enw #1 #2 3 4 5"); + parser.parse("enw 1 2 3 4 5"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'enw' command."); } -Test(ParseServer, enw_wrong_hashtag_egg, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("enw 1 #2 3 4"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'enw' command."); -} - -Test(ParseServer, enw_wrong_hashtag_player, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("enw #1 2 3 4"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'enw' command."); -} - Test(ParseServer, enw_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("enw #1 #2 wrong 4"); + parser.parse("enw 1 2 wrong 4"); } catch (const std::exception &error) { test = error.what(); } @@ -687,7 +544,7 @@ Test(ParseServer, correct_ebo_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("ebo #1"); + test = parser.parse("ebo 1"); cr_assert_eq(test[0], "1"); } @@ -698,33 +555,20 @@ Test(ParseServer, ebo_too_long, .timeout = 5) std::string test; try { - parser.parse("ebo #1 2"); + parser.parse("ebo 1 2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'ebo' command."); } -Test(ParseServer, ebo_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("ebo 1"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'ebo' command."); -} - Test(ParseServer, ebo_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("ebo #wrong"); + parser.parse("ebo wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -738,7 +582,7 @@ Test(ParseServer, correct_edi_command, .timeout = 5) Gui::ServerParser parser; std::vector test; - test = parser.parse("edi #1"); + test = parser.parse("edi 1"); cr_assert_eq(test[0], "1"); } @@ -749,33 +593,20 @@ Test(ParseServer, edi_too_long, .timeout = 5) std::string test; try { - parser.parse("edi #1 2"); + parser.parse("edi 1 2"); } catch (const std::exception &error) { test = error.what(); } cr_assert_str_eq(test.c_str(), "Too many parameters for 'edi' command."); } -Test(ParseServer, edi_wrong_hashtag, .timeout = 5) -{ - Gui::ServerParser parser; - std::string test; - - try { - parser.parse("edi 1"); - } catch (const std::exception &error) { - test = error.what(); - } - cr_assert_str_eq(test.c_str(), "Wrong parameters for 'edi' command."); -} - Test(ParseServer, edi_wrong, .timeout = 5) { Gui::ServerParser parser; std::string test; try { - parser.parse("edi #wrong"); + parser.parse("edi wrong"); } catch (const std::exception &error) { test = error.what(); } @@ -946,3 +777,177 @@ Test(ParseServer, sbp_too_long, .timeout = 5) } cr_assert_str_eq(test.c_str(), "Too many parameters for 'sbp' command."); } + +// command pie + +Test(ParseServer, correct_pie_command, .timeout = 5) +{ + Gui::ServerParser parser; + std::vector test; + + test = parser.parse("pie 1 2 0"); + + cr_assert_eq(test[0], "1"); + cr_assert_eq(test[1], "2"); + cr_assert_eq(test[2], "0"); +} + +Test(ParseServer, pie_too_long, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pie 1 2 3 4"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Too many parameters for 'pie' command."); +} + +Test(ParseServer, pie_wrong, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pie 1 wrong 0"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pie' command."); +} + +// command pbc + +Test(ParseServer, correct_pbc_command, .timeout = 5) +{ + Gui::ServerParser parser; + std::vector test; + + test = parser.parse("pbc 1 test of pbc command 1"); + + cr_assert_eq(test[0], "1"); + cr_assert_eq(test[1], "test of pbc command 1"); +} + +Test(ParseServer, pbc_wrong, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pbc wrong good good good"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pbc' command."); +} + +Test(ParseServer, pbc_no_message, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pbc 1"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pbc' command."); +} + +// command smg + +Test(ParseServer, correct_smg_command, .timeout = 5) +{ + Gui::ServerParser parser; + std::vector test; + + test = parser.parse("smg test of smg command 1"); + + cr_assert_eq(test[0], "test of smg command 1"); +} + +Test(ParseServer, smg_no_message, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("smg "); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'smg' command."); +} + +// command pic + +Test(ParseServer, correct_pic_command, .timeout = 5) +{ + Gui::ServerParser parser; + std::vector test; + + test = parser.parse("pic 1 2 3 9 8 7 6"); + + cr_assert_eq(test[0], "1"); + cr_assert_eq(test[1], "2"); + cr_assert_eq(test[2], "3"); + cr_assert_eq(test[3], "9"); + cr_assert_eq(test[4], "8"); + cr_assert_eq(test[5], "7"); + cr_assert_eq(test[6], "6"); +} + +Test(ParseServer, correct_pic_command_one_list, .timeout = 5) +{ + Gui::ServerParser parser; + std::vector test; + + test = parser.parse("pic 1 2 3 9"); + + cr_assert_eq(test[0], "1"); + cr_assert_eq(test[1], "2"); + cr_assert_eq(test[2], "3"); + cr_assert_eq(test[3], "9"); +} + +Test(ParseServer, pic_no_list, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pic 1 2 3 "); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pic' command."); +} + +Test(ParseServer, pic_wrong_list, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pic 1 2 3 9 8 wrong"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pic' command."); +} + +Test(ParseServer, pic_wrong, .timeout = 5) +{ + Gui::ServerParser parser; + std::string test; + + try { + parser.parse("pic 1 2 wrong 9 8 3"); + } catch (const std::exception &error) { + test = error.what(); + } + cr_assert_str_eq(test.c_str(), "Wrong parameters for 'pic' command."); +}