refactoring for readability
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
#include "test.act.item.h"
|
#include "test.act.item.h"
|
||||||
|
|
||||||
UNIT_TEST(test_do_remove) {
|
|
||||||
|
|
||||||
|
UNIT_TEST(test_do_remove_should_give_message_on_removing_of_unknown_item) {
|
||||||
char_data *ch = create_char();
|
char_data *ch = get_test_char();
|
||||||
CREATE(ch->player_specials, struct player_special_data, 1);
|
|
||||||
new_mobile_data(ch);
|
|
||||||
ch->char_specials.position = POS_STANDING;
|
|
||||||
CREATE(ch->desc, struct descriptor_data, 1);
|
|
||||||
|
|
||||||
char_to_room(ch, 0);
|
|
||||||
|
|
||||||
do_remove(ch, "2.ring", 0, 0);
|
do_remove(ch, "2.ring", 0, 0);
|
||||||
munit_assert_string_equal(get_last_messages(), "You don't seem to be using a ring.\r\n");
|
munit_assert_string_equal(get_last_messages(), "You don't seem to be using a ring.\r\n");
|
||||||
|
|
||||||
|
return MUNIT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UNIT_TEST(test_do_remove_should_remove_second_item_by_number) {
|
||||||
|
char_data *ch = get_test_char();
|
||||||
|
|
||||||
obj_data *ring1 = create_obj();
|
obj_data *ring1 = create_obj();
|
||||||
ring1->name = "ring";
|
ring1->name = "ring";
|
||||||
@@ -26,13 +26,16 @@ UNIT_TEST(test_do_remove) {
|
|||||||
equip_char(ch, ring2, WEAR_FINGER_L);
|
equip_char(ch, ring2, WEAR_FINGER_L);
|
||||||
|
|
||||||
do_remove(ch, "2.ring", 0, 0);
|
do_remove(ch, "2.ring", 0, 0);
|
||||||
|
|
||||||
munit_assert_ptr_equal(ch->carrying, ring2);
|
munit_assert_ptr_equal(ch->carrying, ring2);
|
||||||
|
munit_assert_ptr_equal(ch->carrying->next, ring1);
|
||||||
|
|
||||||
return MUNIT_OK;
|
return MUNIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MunitTest act_item_c_tests[] = {
|
MunitTest act_item_c_tests[] = {
|
||||||
STD_TEST("/do_remove", test_do_remove),
|
STD_TEST("/do_remove/item_not_found", test_do_remove_should_give_message_on_removing_of_unknown_item),
|
||||||
|
STD_TEST("/do_remove/remove_second_item", test_do_remove_should_remove_second_item_by_number),
|
||||||
|
|
||||||
// end of array marker
|
// end of array marker
|
||||||
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
#include "test.handler.h"
|
#include "test.handler.h"
|
||||||
#include "test.act.item.h"
|
#include "test.act.item.h"
|
||||||
|
|
||||||
void simple_world();
|
static void simple_world();
|
||||||
|
static void add_char();
|
||||||
|
|
||||||
|
static char_data* test_char;
|
||||||
|
|
||||||
static MunitSuite suites[] = {
|
static MunitSuite suites[] = {
|
||||||
{ "/handler.c", handler_c_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE },
|
{ "/handler.c", handler_c_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE },
|
||||||
@@ -22,6 +25,7 @@ static const MunitSuite test_suite = {
|
|||||||
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
|
int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
|
||||||
logfile = stderr;
|
logfile = stderr;
|
||||||
simple_world();
|
simple_world();
|
||||||
|
add_char();
|
||||||
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
|
return munit_suite_main(&test_suite, (void*) "µnit", argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +34,29 @@ int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) {
|
|||||||
* test-fixtures common for many tests
|
* test-fixtures common for many tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void simple_world()
|
static void simple_world()
|
||||||
{
|
{
|
||||||
CREATE(world, struct room_data, 1);
|
CREATE(world, struct room_data, 1);
|
||||||
top_of_world = 1;
|
top_of_world = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char_data *get_test_char() {
|
||||||
|
return test_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_char()
|
||||||
|
{
|
||||||
|
char_data *ch = create_char();
|
||||||
|
CREATE(ch->player_specials, struct player_special_data, 1);
|
||||||
|
new_mobile_data(ch);
|
||||||
|
ch->char_specials.position = POS_STANDING;
|
||||||
|
CREATE(ch->desc, struct descriptor_data, 1);
|
||||||
|
|
||||||
|
char_to_room(ch, 0);
|
||||||
|
test_char = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char testbuf[MAX_OUTPUT_BUFFER];
|
static char testbuf[MAX_OUTPUT_BUFFER];
|
||||||
static int testbuf_size = 0;
|
static int testbuf_size = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
/*
|
/*
|
||||||
* test fixtures
|
* test fixtures
|
||||||
*/
|
*/
|
||||||
char_data* create_test_char_data();
|
char_data *get_test_char();
|
||||||
char *get_last_messages();
|
char *get_last_messages();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user