You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1089 lines
27 KiB
1089 lines
27 KiB
//
|
|
// Created by jackyma on 22-6-2.
|
|
//
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <unistd.h>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "gmock/gmock.h"
|
|
using namespace testing;
|
|
#include "server.cpp"
|
|
#include "server.h"
|
|
#include "constants.h"
|
|
#include "common.h"
|
|
#include "func.h"
|
|
|
|
TEST(fun, all_other){
|
|
EXPECT_EQ(1, min(1,2));
|
|
EXPECT_EQ(1, min(2,1));
|
|
|
|
EXPECT_EQ(2, max(1,2));
|
|
EXPECT_EQ(2, max(2,1));
|
|
|
|
EXPECT_EQ(true, probability(1,1));
|
|
myclock();
|
|
|
|
}
|
|
TEST(func3, user_invited_to_join_battle){
|
|
// line 453
|
|
sessions[1].state == USER_STATE_WAIT_TO_BATTLE;
|
|
sessions[1].bid = -1;
|
|
user_invited_to_join_battle(0, 1);
|
|
sessions[1].state == -1;
|
|
sessions[1].bid = -1;
|
|
user_invited_to_join_battle(0, 1);
|
|
sessions[1].state == -1;
|
|
sessions[1].bid = 0;
|
|
user_invited_to_join_battle(0, 1);
|
|
}
|
|
|
|
TEST(func2, user_join_battle){
|
|
// line 447 true
|
|
battles[0].users[0].battle_state == BATTLE_STATE_UNJOINED;
|
|
user_join_battle(0, 0);
|
|
// line 447 false
|
|
battles[0].users[0].battle_state == BATTLE_STATE_LIVE;
|
|
user_join_battle(0, 0);
|
|
}
|
|
|
|
TEST(func1, user_join_battle_common_part){
|
|
user_join_battle_common_part(0, 0, -1); // line 426
|
|
user_join_battle_common_part(0, 0, USER_STATE_BATTLE); // line 419
|
|
user_join_battle_common_part(0, 0, USER_STATE_WAIT_TO_BATTLE); //line 424
|
|
}
|
|
|
|
TEST(func0, all){
|
|
init_constants();
|
|
init_handler();
|
|
|
|
unlink(REGISTERED_USER_FILE);
|
|
load_user_list();
|
|
ofstream userList;
|
|
userList.open(REGISTERED_USER_FILE);
|
|
|
|
char UserName[12] = {"JackyMa"};
|
|
char PassWord[12] = {"abc"};
|
|
userList << "" << endl << "" << endl
|
|
<< UserName << endl << PassWord << endl
|
|
<< UserName << endl << PassWord << endl
|
|
<< UserName << endl << "" << endl;
|
|
//<< "" << endl << "" << endl;
|
|
userList.close();
|
|
load_user_list();
|
|
|
|
unlink(REGISTERED_USER_FILE);
|
|
userList.open(REGISTERED_USER_FILE);
|
|
userList << UserName << endl << PassWord << endl
|
|
<< "" << endl << "" << endl;
|
|
userList.close();
|
|
load_user_list();
|
|
|
|
unlink(REGISTERED_USER_FILE);
|
|
userList.open(REGISTERED_USER_FILE);
|
|
userList << UserName << endl << PassWord << endl
|
|
<< "a" << endl << "" << endl;
|
|
userList.close();
|
|
load_user_list();
|
|
|
|
|
|
save_user_list();
|
|
|
|
save_user(0);
|
|
|
|
client_command_user_register(0);
|
|
|
|
strcpy(sessions[1].cm.user_name, "asdfqwer");
|
|
strcpy(sessions[1].cm.password, "dfqwer");
|
|
client_command_user_register(1);
|
|
|
|
int tmp_user_list_size = user_list_size;
|
|
user_list_size = REGISTERED_USER_LIST_SIZE;
|
|
client_command_user_register(1);
|
|
user_list_size = tmp_user_list_size;
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 5; i++){
|
|
sessions[0].state = i;
|
|
client_command_user_login(0);
|
|
client_command_user_logout(0);
|
|
query_session_built(0);
|
|
}
|
|
|
|
sessions[1].state = -1; // line 321 328 true
|
|
client_command_user_login(0);
|
|
|
|
sessions[1].state = -1; // line 321 328 true
|
|
strcpy(sessions[0].cm.user_name, "test"); // line 330 true
|
|
strcpy(sessions[1].user_name, "test");
|
|
client_command_user_login(0);
|
|
|
|
sessions[1].state = -1; // line 321 328 true
|
|
strcpy(sessions[1].user_name, "test"); // line 330 false
|
|
strcpy(sessions[1].user_name, "test1");
|
|
client_command_user_login(0);
|
|
|
|
|
|
|
|
// 不加任何条件
|
|
user_quit_battle(0, 0);
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].alive_users = 2;
|
|
sessions[0].score = 100;
|
|
sessions[0].death = 0;
|
|
battles[0].all_users = 0;
|
|
user_quit_battle(0, 0);
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].alive_users = 1;
|
|
battles[0].all_users = 1;
|
|
user_quit_battle(0, 0);
|
|
|
|
// line 408 -410
|
|
battles[0].users[0].battle_state = BATTLE_STATE_DEAD;
|
|
battles[0].all_users = 3;
|
|
battles[0].users[1].battle_state = BATTLE_STATE_UNJOINED;
|
|
user_quit_battle(0, 0);
|
|
battles[0].users[0].battle_state = BATTLE_STATE_DEAD;
|
|
battles[0].all_users = 3;
|
|
battles[0].users[1].battle_state = BATTLE_STATE_LIVE;
|
|
user_quit_battle(0, 0);
|
|
battles[0].users[0].battle_state = BATTLE_STATE_DEAD;
|
|
battles[0].all_users = 3;
|
|
battles[0].users[1].battle_state = BATTLE_STATE_LIVE;
|
|
sessions[1].conn = 0;
|
|
user_quit_battle(0, 0);
|
|
|
|
}
|
|
|
|
TEST(func4, find_uid_by_user_name){
|
|
sessions[0].state == USER_STATE_UNUSED; // query_session_built false
|
|
char user_name = 'a';
|
|
find_uid_by_user_name(&user_name);
|
|
|
|
sessions[0].state == -1; // query_session_built true
|
|
strcpy(sessions[1].user_name, "a");
|
|
find_uid_by_user_name(&user_name);
|
|
}
|
|
|
|
TEST(func5, get_unalloced_battle){
|
|
get_unalloced_battle();
|
|
for (int i = 1; i < USER_CNT; i++){
|
|
battles[i].is_alloced = true;
|
|
}
|
|
get_unalloced_battle();
|
|
}
|
|
|
|
TEST(func5, get_unused_session){
|
|
get_unused_session();
|
|
for (int i = 0; i < USER_CNT; i++){
|
|
sessions[i].state = -1;
|
|
}
|
|
get_unused_session();
|
|
}
|
|
|
|
TEST(func6, forced_generate_items){
|
|
// line 541 542 x y
|
|
forced_generate_items(0,-1,-1,0,0,-1);
|
|
forced_generate_items(0,61,22,0,0,-1);
|
|
forced_generate_items(0,1,-1,0,0,-1);
|
|
forced_generate_items(0,1,22,0,0,-1);
|
|
forced_generate_items(0,1,1,ITEM_MAGMA,0,-1);
|
|
forced_generate_items(0,1,1,-1,0,-1);
|
|
}
|
|
|
|
TEST(func7, random_generate_items){
|
|
battles[0].num_of_other = 22;
|
|
random_generate_items(0); // line 568 return
|
|
battles[0].num_of_other = 1;
|
|
random_generate_items(0);
|
|
}
|
|
|
|
TEST(func8, move_bullets){
|
|
move_bullets(0);
|
|
item_t it = item_t();
|
|
list<item_t> items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0);
|
|
|
|
it.kind = ITEM_BULLET;
|
|
it.dir = DIR_UP;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items; // line 613
|
|
move_bullets(0); // DIR_UP if
|
|
it.pos.y = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // else
|
|
|
|
it.dir = DIR_DOWN;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_DOWN if
|
|
move_bullets(0);
|
|
it.pos.y = 100;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_DOWN else
|
|
move_bullets(0);
|
|
|
|
it.dir = DIR_LEFT;
|
|
it.pos.x = 1;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_LEFT if
|
|
move_bullets(0);
|
|
it.pos.x = 0;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_LEFT else
|
|
move_bullets(0);
|
|
|
|
it.dir = DIR_RIGHT;
|
|
it.pos.x = 1;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_RIGHT if
|
|
move_bullets(0);
|
|
it.pos.x = 100;
|
|
items = {it};
|
|
battles[0].items = items; // DIR_RIGHT else
|
|
move_bullets(0);
|
|
|
|
it.dir = DIR_UP_LEFT;
|
|
it.pos.x = 1;
|
|
it.pos.y = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // _ f
|
|
it.pos.x = 1;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // f t
|
|
it.pos.x = 2;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // t t
|
|
|
|
it.dir = DIR_UP_RIGHT;
|
|
it.pos.x = 1;
|
|
it.pos.y = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // _ f
|
|
it.pos.x = BATTLE_W;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // f t
|
|
it.pos.x = BATTLE_W - 4;
|
|
it.pos.y = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // t t
|
|
|
|
it.dir = DIR_DOWN_RIGHT;
|
|
it.pos.x = 1;
|
|
it.pos.y = BATTLE_H;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // _ f
|
|
it.pos.x = BATTLE_W;
|
|
it.pos.y = BATTLE_H - 4;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // f t
|
|
it.pos.x = BATTLE_W - 4;
|
|
it.pos.y = BATTLE_H - 4;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // t t
|
|
|
|
it.dir = DIR_DOWN_LEFT;
|
|
it.pos.x = 1;
|
|
it.pos.y = BATTLE_H;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // _ f
|
|
it.pos.x = 1;
|
|
it.pos.y = BATTLE_H - 4;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // f t
|
|
it.pos.x = 2;
|
|
it.pos.y = BATTLE_H - 4;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0); // t t
|
|
|
|
it.dir = 9;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
move_bullets(0);
|
|
}
|
|
|
|
|
|
TEST(func9, check_all_user_status){
|
|
check_all_user_status(0);
|
|
}
|
|
|
|
TEST(func10, check_who_is_dead){
|
|
check_who_is_dead(0);
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].users[0].life = 0;
|
|
battles[0].users[0].killby = 1; // by = 1
|
|
sessions[1].kill = 0; //sessions[by].kill++; 1
|
|
sessions[0].score = 3;
|
|
sessions[1].score = 1;
|
|
check_who_is_dead(0);
|
|
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].users[0].life = 0;
|
|
battles[0].users[0].killby = 1; // by = 1
|
|
sessions[1].kill = 0; //sessions[by].kill++; 1
|
|
sessions[0].score = 1;
|
|
sessions[1].score = 10;
|
|
check_who_is_dead(0);
|
|
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].users[0].life = 0;
|
|
battles[0].users[0].killby = -1;
|
|
check_who_is_dead(0); // if if
|
|
|
|
battles[0].users[0].battle_state = BATTLE_STATE_DEAD;
|
|
battles[0].users[0].life = 1;
|
|
check_who_is_dead(0);
|
|
}
|
|
|
|
TEST(func11, check_user_status){
|
|
check_user_status(0);
|
|
sessions[0].bid = 0;
|
|
battles[0].users[0].battle_state = BATTLE_STATE_LIVE;
|
|
item_t it = item_t();
|
|
list<item_t> items = {};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
items = {it, it, it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
battles[0].users[0].pos.x = 1;
|
|
battles[0].users[0].pos.y = 1;
|
|
it.pos.x=1;
|
|
it.pos.y=0; // ix == ux && iy == uy t f
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
|
|
it.pos.x=1;
|
|
it.pos.y=1; // ix == ux && iy == uy t t
|
|
it.kind = -1; // default
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
|
|
it.kind = ITEM_MAGAZINE;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
battles[0].users[0].energy = 0;
|
|
check_user_status(0);
|
|
battles[0].items = items;
|
|
battles[0].users[0].energy = MAX_BULLETS;
|
|
check_user_status(0);
|
|
|
|
it.kind = ITEM_MAGMA;
|
|
it.owner = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
it.owner = 1;
|
|
it.count = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
it.count = 2;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
|
|
it.kind = ITEM_BLOOD_VIAL;
|
|
battles[0].users[0].life = MAX_LIFE - LIFE_PER_VIAL;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
battles[0].users[0].life = MAX_LIFE + 10;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
|
|
it.kind = ITEM_BULLET;
|
|
it.owner = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
it.owner = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
|
|
it.kind = ITEM_LANDMINE;
|
|
it.owner = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
it.owner = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
check_user_status(0);
|
|
}
|
|
|
|
TEST(func12, clear_items){
|
|
clear_items(0);
|
|
item_t it = item_t();
|
|
it.time = 0;
|
|
list<item_t> items = {it};
|
|
battles[0].items = items;
|
|
battles[0].global_time = 0;
|
|
clear_items(0);
|
|
|
|
it.time = 10;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
battles[0].global_time = 0;
|
|
clear_items(0);
|
|
}
|
|
|
|
TEST(func13, render_map_for_user){
|
|
server_message_t psm;
|
|
sessions[0].bid = 0;
|
|
item_t it = item_t();
|
|
list<item_t> items = {it};
|
|
battles[0].items = items;
|
|
render_map_for_user(0, &psm); // default
|
|
|
|
it.kind = ITEM_BULLET;
|
|
it.owner = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
render_map_for_user(0, &psm);
|
|
it.owner = -1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
render_map_for_user(0, &psm);
|
|
|
|
it.kind = ITEM_LANDMINE;
|
|
it.owner = 0;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
render_map_for_user(0, &psm);
|
|
it.owner = 1;
|
|
items = {it};
|
|
battles[0].items = items;
|
|
render_map_for_user(0, &psm);
|
|
}
|
|
|
|
TEST(func14, inform_all_user_battle_player){
|
|
inform_all_user_battle_player(0);
|
|
battles[0].users[2].battle_state = BATTLE_STATE_LIVE;
|
|
battles[0].users[2].life = 0;
|
|
inform_all_user_battle_player(0);
|
|
}
|
|
|
|
TEST(func15, inform_all_user_battle_state){
|
|
inform_all_user_battle_state(0);
|
|
}
|
|
|
|
TEST(func16, launch_battle){
|
|
launch_battle(-1);
|
|
}
|
|
|
|
TEST(func17, battle_ruler){
|
|
battles[0].is_alloced = 1;
|
|
battles[0].global_time = 9;
|
|
launch_battle(0);
|
|
}
|
|
|
|
TEST(func18, check_user_registered){
|
|
unlink(REGISTERED_USER_FILE);
|
|
ofstream userList;
|
|
userList.open(REGISTERED_USER_FILE);
|
|
userList << "test" << endl << "asd" << endl;
|
|
userList.close();
|
|
char user_name[12] = {"test"};
|
|
char password[12] = {"asd"};
|
|
check_user_registered(user_name, password);
|
|
unlink(REGISTERED_USER_FILE);
|
|
userList.open(REGISTERED_USER_FILE);
|
|
userList << "test" << endl << "asd" << endl;
|
|
userList.close();
|
|
char password1[12] = {"asda"};
|
|
strcpy(registered_user_list[0].user_name, user_name);
|
|
strcpy(registered_user_list[0].password, password);
|
|
check_user_registered(user_name, password1);
|
|
}
|
|
|
|
TEST(func19, client_command_fetch_all_users){
|
|
sessions[0].state = -1;
|
|
client_command_fetch_all_users(0);
|
|
sessions[0].state = USER_STATE_UNUSED;
|
|
client_command_fetch_all_users(0);
|
|
}
|
|
|
|
TEST(func20, client_command_fetch_all_friends){
|
|
sessions[0].state = -1;
|
|
client_command_fetch_all_friends(0);
|
|
sessions[0].state = USER_STATE_UNUSED;
|
|
client_command_fetch_all_friends(0);
|
|
}
|
|
|
|
TEST(func21, invite_friend_to_battle){
|
|
char friend_name[12] = {"JackyMa"};
|
|
invite_friend_to_battle(0,0, friend_name);
|
|
}
|
|
|
|
TEST(func22, client_command_launch_battle){
|
|
client_command_launch_battle(0);
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_launch_battle(0);
|
|
sessions[0].state = -1;
|
|
for (int i = 1; i < USER_CNT; i++) {
|
|
battles[i].is_alloced = false;
|
|
}
|
|
client_command_launch_battle(0);
|
|
sessions[0].state = -1;
|
|
for (int i = 1; i < USER_CNT; i++) {
|
|
battles[i].is_alloced = false;
|
|
}
|
|
strcpy(sessions[0].cm.user_name, "");
|
|
client_command_launch_battle(0);
|
|
}
|
|
|
|
TEST(func23, client_command_quit_battle){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_quit_battle(0);
|
|
sessions[0].state = -1;
|
|
client_command_quit_battle(0);
|
|
}
|
|
|
|
TEST(func24, client_command_invite_user){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_invite_user(0);
|
|
sessions[0].state = -1;
|
|
client_command_invite_user(0);
|
|
}
|
|
|
|
TEST(func25, client_command_send_message){
|
|
strcpy(sessions[0].cm.user_name, "\0a");
|
|
client_command_send_message(0);
|
|
strcpy(sessions[0].cm.user_name, "test");
|
|
client_command_send_message(0);
|
|
}
|
|
|
|
TEST(func26, client_command_create_ffa){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
battles[0].is_alloced = 1;
|
|
client_command_create_ffa(0);
|
|
sessions[0].state = -1;
|
|
battles[0].is_alloced = 1;
|
|
client_command_create_ffa(0);
|
|
sessions[0].state = -1;
|
|
battles[0].is_alloced = 0;
|
|
strcpy(sessions[0].cm.user_name, "");
|
|
client_command_create_ffa(0);
|
|
strcpy(sessions[0].cm.user_name, "test");
|
|
client_command_create_ffa(0);
|
|
}
|
|
|
|
TEST(func27, client_command_launch_ffa){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_launch_ffa(0);
|
|
sessions[0].state = -1;
|
|
battles[0].is_alloced = true;
|
|
client_command_launch_ffa(0);
|
|
sessions[0].state = -1;
|
|
battles[0].is_alloced = false;
|
|
client_command_launch_ffa(0);
|
|
}
|
|
|
|
TEST(func28, client_command_accept_battle){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_accept_battle(0);
|
|
sessions[0].state = USER_STATE_WAIT_TO_BATTLE;
|
|
sessions[0].bid = 1;
|
|
battles[1].is_alloced = true;
|
|
client_command_accept_battle(0);
|
|
sessions[0].state = USER_STATE_WAIT_TO_BATTLE;
|
|
sessions[0].bid = 1;
|
|
battles[1].is_alloced = false;
|
|
client_command_accept_battle(0);
|
|
sessions[0].state = -1;
|
|
client_command_accept_battle(0);
|
|
}
|
|
|
|
TEST(func29, client_command_reject_battle){
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_reject_battle(0);
|
|
sessions[0].state = USER_STATE_WAIT_TO_BATTLE;
|
|
client_command_reject_battle(0);
|
|
sessions[0].state = -1;
|
|
client_command_reject_battle(0);
|
|
}
|
|
|
|
TEST(func30, client_command_quit){
|
|
sessions[0].conn = 0;
|
|
sessions[0].state = USER_STATE_BATTLE;
|
|
client_command_quit(0);
|
|
sessions[0].state = USER_STATE_WAIT_TO_BATTLE;
|
|
client_command_quit(0);
|
|
sessions[0].conn = -1;
|
|
sessions[0].state = -1;
|
|
client_command_quit(0);
|
|
}
|
|
|
|
TEST(func31, client_command_move_up){
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].pos.y = 0;
|
|
client_command_move_up(0);
|
|
battles[1].users[0].pos.y = 1;
|
|
client_command_move_up(0);
|
|
}
|
|
|
|
TEST(func32, client_command_move_down){
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].pos.y = BATTLE_H - 1;
|
|
client_command_move_down(0);
|
|
battles[1].users[0].pos.y = BATTLE_H - 2;
|
|
client_command_move_down(0);
|
|
}
|
|
|
|
TEST(func33, client_command_move_left){
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].pos.x = 0;
|
|
client_command_move_left(0);
|
|
battles[1].users[0].pos.x = 1;
|
|
client_command_move_left(0);
|
|
}
|
|
|
|
TEST(func34, client_command_move_right){
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].pos.x = BATTLE_W - 1;
|
|
client_command_move_right(0);
|
|
battles[1].users[0].pos.x = BATTLE_W - 2;
|
|
client_command_move_right(0);
|
|
}
|
|
|
|
TEST(func35, client_command_fire){
|
|
client_command_fire_up(0);
|
|
client_command_fire_down(0);
|
|
client_command_fire_left(0);
|
|
client_command_fire_right(0);
|
|
client_command_fire_up_left(0);
|
|
client_command_fire_up_right(0);
|
|
client_command_fire_down_left(0);
|
|
client_command_fire_down_right(0);
|
|
}
|
|
|
|
TEST(func36, list_all_users){
|
|
server_message_t psm;
|
|
sessions[0].state = USER_STATE_UNUSED;
|
|
list_all_users(&psm);
|
|
}
|
|
|
|
TEST(func37, client_command_fire){
|
|
//uid = 0 bid = 1
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].energy = 0;
|
|
client_command_fire(0,0,0,0);
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].energy = 10;
|
|
client_command_fire(0,0,0,0);
|
|
battles[1].users[0].pos.x = -1;
|
|
client_command_fire(0,0,0,0);
|
|
battles[1].users[0].pos.x = BATTLE_W;
|
|
client_command_fire(0,0,0,0);
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].energy = 10;
|
|
battles[1].users[0].pos.x = 0;
|
|
client_command_fire(0,0,0,0);
|
|
|
|
battles[1].users[0].pos.y = -1;
|
|
client_command_fire(0,0,0,0);
|
|
battles[1].users[0].pos.y = BATTLE_H;
|
|
client_command_fire(0,0,0,0);
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].energy = 10;
|
|
battles[1].users[0].pos.y = 0;
|
|
client_command_fire(0,0,0,0);
|
|
}
|
|
|
|
TEST(func38, client_command_fire_aoe){
|
|
client_command_fire_aoe_up(0);
|
|
client_command_fire_aoe_down(0);
|
|
client_command_fire_aoe_left(0);
|
|
client_command_fire_aoe_right(0);
|
|
client_command_fire_aoe(0, -1);
|
|
}
|
|
|
|
TEST(func39, client_command_melee){
|
|
client_command_melee(0);
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].life = 0;
|
|
client_command_melee(0);
|
|
}
|
|
|
|
TEST(func40, client_command_put_landmine){
|
|
//uid = 0 bid = 1
|
|
sessions[0].bid = 1;
|
|
battles[1].users[0].energy = LANDMINE_COST - 2;
|
|
client_command_put_landmine(0);
|
|
battles[1].users[0].energy = LANDMINE_COST;
|
|
battles[1].users[0].pos.x = BATTLE_W;
|
|
client_command_put_landmine(0);
|
|
battles[1].users[0].energy = LANDMINE_COST;
|
|
battles[1].users[0].pos.x = 1;
|
|
client_command_put_landmine(0);
|
|
battles[1].users[0].energy = LANDMINE_COST;
|
|
battles[1].users[0].pos.y = BATTLE_H;
|
|
client_command_put_landmine(0);
|
|
battles[1].users[0].energy = LANDMINE_COST;
|
|
battles[1].users[0].pos.y = 1;
|
|
client_command_put_landmine(0);
|
|
}
|
|
|
|
TEST(func41, client_command_admin_control){
|
|
sessions[0].is_admin = false;
|
|
client_command_admin_control(0);
|
|
sessions[0].is_admin = true;
|
|
|
|
strcpy(sessions[0].cm.message, "hello");
|
|
client_command_admin_control(0);
|
|
}
|
|
|
|
TEST(func42, admin_set_admin){
|
|
string user_name = "test@";
|
|
char* str0 = new char[5];
|
|
strcpy(str0, user_name.c_str());
|
|
|
|
string status = "1";
|
|
char* str1 = new char[5];
|
|
strcpy(str1, status.c_str());
|
|
|
|
char** argv = new char*[5];
|
|
argv[1] = str0;
|
|
argv[2] = str1;
|
|
|
|
admin_set_admin(0, argv);
|
|
admin_set_admin(3, argv);
|
|
sessions[0].state = USER_STATE_LOGIN;
|
|
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
admin_set_admin(3, argv);
|
|
sessions[0].conn = 0;
|
|
admin_set_admin(3, argv);
|
|
|
|
status = "0";
|
|
strcpy(str1, status.c_str());
|
|
argv[2] = str1;
|
|
admin_set_admin(3, argv);
|
|
}
|
|
|
|
TEST(func43, admin_set_energy){
|
|
string user_name = "test@";
|
|
char* str0 = new char[5];
|
|
strcpy(str0, user_name.c_str());
|
|
|
|
string energy = "1";
|
|
char* str1 = new char[5];
|
|
strcpy(str1, energy.c_str());
|
|
|
|
char** argv = new char*[5];
|
|
argv[1] = str0;
|
|
argv[2] = str1;
|
|
|
|
admin_set_energy(1, argv);
|
|
sessions[0].state = USER_STATE_LOGIN;
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
admin_set_energy(4, argv);
|
|
sessions[0].conn = -1;
|
|
energy = "-1";
|
|
strcpy(str1, energy.c_str());
|
|
argv[2] = str1;
|
|
admin_set_energy(3, argv);
|
|
sessions[0].conn = 0;
|
|
admin_set_energy(3, argv);
|
|
user_name = "test@asd";
|
|
strcpy(str0, user_name.c_str());
|
|
argv[1] = str0;
|
|
admin_set_energy(4, argv);
|
|
}
|
|
|
|
TEST(func44, admin_set_hp){
|
|
string user_name = "test@";
|
|
char* str0 = new char[5];
|
|
strcpy(str0, user_name.c_str());
|
|
|
|
string hp = "1";
|
|
char* str1 = new char[5];
|
|
strcpy(str1, hp.c_str());
|
|
|
|
char** argv = new char*[5];
|
|
argv[1] = str0;
|
|
argv[2] = str1;
|
|
|
|
admin_set_hp(1, argv);
|
|
sessions[0].state = USER_STATE_LOGIN;
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
admin_set_hp(4, argv);
|
|
sessions[0].conn = -1;
|
|
hp = "-1";
|
|
strcpy(str1, hp.c_str());
|
|
argv[2] = str1;
|
|
admin_set_hp(3, argv);
|
|
sessions[0].conn = 0;
|
|
admin_set_hp(3, argv);
|
|
user_name = "test@asd";
|
|
strcpy(str0, user_name.c_str());
|
|
argv[1] = str0;
|
|
admin_set_hp(4, argv);
|
|
}
|
|
|
|
TEST(func45, admin_set_pos){
|
|
string user_name = "test@";
|
|
char* str0 = new char[5];
|
|
strcpy(str0, user_name.c_str());
|
|
|
|
int x = -1;
|
|
char* str1 = new char[5];
|
|
strcpy(str1, to_string(x).c_str());
|
|
int y = -1;
|
|
char* str2 = new char[5];
|
|
strcpy(str2, to_string(y).c_str());
|
|
|
|
char** argv = new char*[5];
|
|
argv[1] = str0;
|
|
argv[2] = str1;
|
|
argv[3] = str2;
|
|
admin_set_pos(0, argv);
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
admin_set_pos(4, argv);
|
|
sessions[0].conn = -1;
|
|
admin_set_pos(4, argv);
|
|
user_name = "test@123456";
|
|
strcpy(str0, user_name.c_str());
|
|
argv[1] = str0;
|
|
admin_set_pos(4, argv);
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
sessions[0].conn = 0;
|
|
admin_set_pos(5, argv);
|
|
x = 61;
|
|
strcpy(str1, to_string(x).c_str());
|
|
argv[2] = str1;
|
|
admin_set_pos(5, argv);
|
|
x = 41;
|
|
strcpy(str1, to_string(x).c_str());
|
|
argv[2] = str1;
|
|
admin_set_pos(5, argv);
|
|
y=25;
|
|
strcpy(str2, to_string(y).c_str());
|
|
argv[3] = str2;
|
|
admin_set_pos(5, argv);
|
|
y=2;
|
|
strcpy(str2, to_string(y).c_str());
|
|
argv[3] = str2;
|
|
admin_set_pos(5, argv);
|
|
}
|
|
|
|
TEST(func46, admin_ban_user){
|
|
string user_name = "test@";
|
|
char* str0 = new char[5];
|
|
strcpy(str0, user_name.c_str());
|
|
|
|
char** argv = new char*[5];
|
|
argv[1] = str0;
|
|
admin_ban_user(0, argv);
|
|
admin_ban_user(3, argv);
|
|
strcpy(sessions[0].user_name, user_name.c_str());
|
|
sessions[0].conn = -1;
|
|
admin_ban_user(3, argv);
|
|
sessions[0].conn = 0;
|
|
admin_ban_user(3, argv);
|
|
}
|
|
|
|
TEST(func47, client_message_fatal){
|
|
client_message_fatal(0);
|
|
|
|
char message = 'a';
|
|
sessions[0].conn = -1;
|
|
send_to_client(0, -1);
|
|
sessions[0].conn = 1;
|
|
send_to_client(0, -1);
|
|
|
|
sessions[0].conn = -1;
|
|
send_to_client(0, 0, &message);
|
|
sessions[0].conn = -1;
|
|
say_to_client(0, &message);
|
|
sessions[0].conn = -1;
|
|
send_to_client_with_username(0,0,&message);
|
|
|
|
sessions[0].conn = 1;
|
|
send_to_client(0, 0, &message);
|
|
sessions[0].conn = 1;
|
|
say_to_client(0, &message);
|
|
sessions[0].conn = 1;
|
|
send_to_client_with_username(0,0,&message);
|
|
close_session(0,0);
|
|
server_start();
|
|
|
|
terminate_process(0);
|
|
terminate_process(1);
|
|
server_fd = 1;
|
|
sessions[0].conn = 0;
|
|
terminate_process(1);
|
|
terminate_entrance(0);
|
|
terminate_entrance(2);
|
|
|
|
}
|
|
|
|
TEST(func48, session_start){
|
|
session_args_t t = {.conn = 0};
|
|
void* args = &t;
|
|
session_start(args);
|
|
|
|
run_battle(args);
|
|
char ip[24] = {"127.0.0.1"};
|
|
|
|
strcpy(t.ip_addr, ip);
|
|
for(int i =0;i<8;i++){
|
|
sessions[i].state = -1;
|
|
}
|
|
sessions[8].state = USER_STATE_UNUSED;
|
|
sessions[0].cm.command = -1;
|
|
session_start(args);
|
|
}
|
|
|
|
TEST(func49, client_command_user_login){
|
|
for(int i =0; i< USER_CNT;i++){
|
|
sessions[i].state = USER_STATE_UNUSED;
|
|
}
|
|
cout<<"as:"<<endl;
|
|
client_command_user_login(0);
|
|
}
|
|
|
|
TEST(func50, add){
|
|
user_list_size = 100;
|
|
strcpy(sessions[0].cm.user_name, "154254");
|
|
client_command_user_register(0);
|
|
unlink(REGISTERED_USER_FILE);
|
|
ofstream userList;
|
|
userList.open(REGISTERED_USER_FILE);
|
|
for(int i =0; i <REGISTERED_USER_LIST_SIZE*2-1; i++){
|
|
|
|
userList<<i<<endl;
|
|
}
|
|
for (int i = 0; i < REGISTERED_USER_LIST_SIZE; i++){
|
|
int a = 2*i;
|
|
int b =2*i+1;
|
|
strcpy(registered_user_list[i].user_name,to_string(a).c_str());
|
|
if(i!=9){
|
|
strcpy(registered_user_list[i].password,to_string(b).c_str());
|
|
}
|
|
|
|
}
|
|
userList.close();
|
|
load_user_list();
|
|
unlink(REGISTERED_USER_FILE);
|
|
userList.open(REGISTERED_USER_FILE);
|
|
for(int i =0; i <REGISTERED_USER_LIST_SIZE*2; i++){
|
|
userList<<i<<endl;
|
|
}
|
|
load_user_list();
|
|
client_command_user_register(0);
|
|
|
|
char friend_name[12] = {"last_one"};
|
|
|
|
strcpy(sessions[5].user_name, "last_one"); //fuid = 5
|
|
sessions[5].state = USER_STATE_BATTLE;
|
|
invite_friend_to_battle(0, 6, friend_name);
|
|
sessions[5].state = -1;
|
|
invite_friend_to_battle(0, 6, friend_name);
|
|
|
|
init_constant();
|
|
char url[24] = {"127.0.0.1"};
|
|
init_handlers(url);
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(func52, algorithm){
|
|
EightQueen(8);
|
|
|
|
EightQueen1();
|
|
floyd_algorithm::floyd();
|
|
using namespace floyd_algorithm;
|
|
ListGraph* LG;
|
|
MatGraph MG;
|
|
|
|
int array[MAXV][MAXV] = {
|
|
{ 0, 4, 6, 6,INF,INF,INF},
|
|
{INF, 0, 1,INF, 7,INF,INF},
|
|
{INF,INF, 0,INF, 6, 4,INF},
|
|
{INF,INF, 2, 0,INF, 5,INF},
|
|
{INF,INF,INF,INF, 0,INF, 6},
|
|
{INF,INF,INF,INF, 1, 0, 8},
|
|
{INF,INF,INF,INF,INF,INF, 0}
|
|
};
|
|
|
|
int e = 12;
|
|
createAdjListGraph(LG, array, MAXV, e);
|
|
displayAdjList(LG);
|
|
printf("\n");
|
|
ListToMat(LG, MG);
|
|
displayAdjMat(MG);
|
|
printf("\n");
|
|
Floyd(MG);
|
|
printf("\n");
|
|
|
|
|
|
EightQueen(-1);}
|
|
|
|
TEST(func53, add_locs){
|
|
__floyd::floyd();
|
|
using namespace __floyd;
|
|
ListGraph* LG;
|
|
MatGraph MG;
|
|
|
|
int array[MAXV][MAXV] = {
|
|
{ 0, 4, 6, 6,INF,INF,INF},
|
|
{INF, 0, 1,INF, 7,INF,INF},
|
|
{INF,INF, 0,INF, 6, 4,INF},
|
|
{INF,INF, 2, 0,INF, 5,INF},
|
|
{INF,INF,INF,INF, 0,INF, 6},
|
|
{INF,INF,INF,INF, 1, 0, 8},
|
|
{INF,INF,INF,INF,INF,INF, 0}
|
|
};
|
|
|
|
int e = 12;
|
|
createAdjListGraph(LG, array, MAXV, e);
|
|
displayAdjList(LG);
|
|
printf("\n");
|
|
ListToMat(LG, MG);
|
|
displayAdjMat(MG);
|
|
printf("\n");
|
|
Floyd(MG);
|
|
printf("\n");
|
|
|
|
using namespace Queue;
|
|
Queue::EightQueen1();
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
|
testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|
|
|