void testString() { JSONParser *parser; tryStringOk("\"test\" ", [](const char *const atom) { assertStringEqual(atom, "test"); }); tryStringOk("\"\\\\\" ", [](const char *const atom) { assertStringEqual(atom, "\\\\"); }); tryStringOk("\" \" ", [](const char *const atom) { assertStringEqual(atom, " "); }); tryStringOk("\"\\\"\" ", [](const char *const atom) { assertStringEqual(atom, "\\\""); }); tryStringOk("\"te\\nst\" ", [](const char *const atom) { assertStringEqual(atom, "te\\nst"); }); tryStringFail("\" "); tryStringFail("\"\\ \" "); tryStringFail("\"\n\" "); }
void client_connect_callback(ipp_socket * sock) { ipp_player *player; printf("client_connect_callback()\n"); player = ipp_server_handshake(sock, "testd/1.0", auth, logger); if (player == NULL) { ipp_free_socket(sock); sock = NULL; assertNotNull("ipp_server_handshake() returned NULL", player); ipp_servloop_shutdown(); return; } assertStringEqual("Player name fail", "JSMITH", player->name); ipp_free_player(player); player = NULL; ipp_servloop_shutdown(); return; }
int main() { ipp_message *msg; ipp_card *Kh; ipp_card *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHTFLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHT); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FLUSH A K Q J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FLUSH); assertEqual("Didn't detect proper hand.", msg->type, MSG_FLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Ks; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_ONEPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_TWOPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FULLHOUSE); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A J", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_THREEOFAKIND); ipp_free_message(msg); hand[0] = Kh; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K J", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FOUROFAKIND); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_HIGHCARD); ipp_free_message(msg); ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Kh); ipp_exit(); return PASS; }
int main() { ipp_message *msg; ipp_card *Ks, *Kd, *Kh, *Kc; ipp_card *As, *Ad, *Ah; ipp_player *player; ipp_table *table; int rc, i; ipp_init(); table = ipp_new_table(); player = ipp_new_player(); assertNotNull("Table should not be null.", table); assertNotNull("Player should not be null.", player); assertEqual("Table shouldn't have any players", table->nplayers, 0); rc = ipp_add_player(table, player); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have one player", table->nplayers, 1); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; Ah = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ah); Ah->rank = ACE; Ah->suit = HEARTS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; table->board[0] = Ad; table->board[1] = Ah; table->board[2] = Kd; table->board[3] = Kh; table->board[4] = Kc; table->players[0]->hole[0] = As; table->players[0]->hole[1] = Ks; table->stage = SHOWDOWN; msg = ipp_best_combination(table, 0); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("%s\n", msg->payload); assertStringEqual("Out of Ad Ah As Kd Ks Kh Kc, FOUROFAKIND K A should be the best hand.", "FOUROFAKIND K A", msg->payload); ipp_free_message(msg); ipp_free_table(table); /* will also free player */ ipp_exit(); return PASS; }
int main() { ipp_message *msga, *msgb; ipp_card *Kh; ipp_card *Ac, *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_9s, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Ac = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ac); Ac->rank = ACE; Ac->suit = CLUBS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _9s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _9s); _9s->rank = NINE; _9s->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_HIGHCARD); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = Ks; hand[1] = Qs; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHTFLUSH); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Kd; hand[3] = Kh; hand[4] = Kc; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FOUROFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FOUROFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = Kh; hand[3] = Kc; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FOUROFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHT); hand[0] = Qs; hand[1] = Kd; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHT K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHT); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ad; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE A K", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FULLHOUSE); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = Kh; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FULLHOUSE); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ts; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K T", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_TWOPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_TWOPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = Ac; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND A T 9", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_THREEOFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Kh; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_THREEOFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = _7s; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A 9 7", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_ONEPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); assertEqual("msga should beat NULL", 1, ipp_hand_compar(msga, NULL)); assertEqual("msga should beat NULL", -1, ipp_hand_compar(NULL, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); assertEqual("NULL should equal NULL", 0, ipp_hand_compar(NULL, NULL)); ipp_free_message(msga); /* =-=-=-=-=-= */ ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(_9s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Ac); ipp_free_card(Kh); ipp_exit(); return PASS; }