mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-17 04:51:52 +00:00
Added: New unit tests for common.h
This commit is contained in:
parent
1978cab022
commit
54001f553d
2 changed files with 108 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "ut_misc_co_task.h"
|
#include "ut_misc_co_task.h"
|
||||||
#include "ut_misc_command.h"
|
#include "ut_misc_command.h"
|
||||||
|
#include "ut_misc_common.h"
|
||||||
#include "ut_misc_config_file.h"
|
#include "ut_misc_config_file.h"
|
||||||
#include "ut_misc_debug.h"
|
#include "ut_misc_debug.h"
|
||||||
#include "ut_misc_dynlibload.h"
|
#include "ut_misc_dynlibload.h"
|
||||||
|
@ -38,6 +39,7 @@ struct CUTMisc : public Test::Suite
|
||||||
{
|
{
|
||||||
add(auto_ptr<Test::Suite>(new CUTMiscCoTask));
|
add(auto_ptr<Test::Suite>(new CUTMiscCoTask));
|
||||||
add(auto_ptr<Test::Suite>(new CUTMiscCommand));
|
add(auto_ptr<Test::Suite>(new CUTMiscCommand));
|
||||||
|
add(auto_ptr<Test::Suite>(new CUTMiscCommon));
|
||||||
add(auto_ptr<Test::Suite>(new CUTMiscConfigFile));
|
add(auto_ptr<Test::Suite>(new CUTMiscConfigFile));
|
||||||
add(auto_ptr<Test::Suite>(new CUTMiscDebug));
|
add(auto_ptr<Test::Suite>(new CUTMiscDebug));
|
||||||
add(auto_ptr<Test::Suite>(new CUTMiscDynLibLoad));
|
add(auto_ptr<Test::Suite>(new CUTMiscDynLibLoad));
|
||||||
|
|
106
code/nel/tools/nel_unit_test/ut_misc_common.h
Normal file
106
code/nel/tools/nel_unit_test/ut_misc_common.h
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef UT_MISC_COMMON
|
||||||
|
#define UT_MISC_COMMON
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <nel/misc/common.h>
|
||||||
|
|
||||||
|
struct CUTMiscCommon : public Test::Suite
|
||||||
|
{
|
||||||
|
CUTMiscCommon()
|
||||||
|
{
|
||||||
|
TEST_ADD(CUTMiscCommon::humanReadableToBytes);
|
||||||
|
|
||||||
|
// Add a line here when adding a new test METHOD
|
||||||
|
}
|
||||||
|
|
||||||
|
void humanReadableToBytes()
|
||||||
|
{
|
||||||
|
uint64 bytes = 0;
|
||||||
|
|
||||||
|
// kiB is a wrong unit
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1kiB");
|
||||||
|
TEST_ASSERT(bytes == 1);
|
||||||
|
|
||||||
|
// 1 kibibyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1KiB");
|
||||||
|
TEST_ASSERT(bytes == 1024);
|
||||||
|
|
||||||
|
// 1 mebibyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1MiB");
|
||||||
|
TEST_ASSERT(bytes == 1024*1024);
|
||||||
|
|
||||||
|
// 1 kilobyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1KB");
|
||||||
|
TEST_ASSERT(bytes == 1000);
|
||||||
|
|
||||||
|
// 1 kilobyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1kB");
|
||||||
|
TEST_ASSERT(bytes == 1000);
|
||||||
|
|
||||||
|
// 1 megabyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1MB");
|
||||||
|
TEST_ASSERT(bytes == 1000*1000);
|
||||||
|
|
||||||
|
// 1 byte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1B");
|
||||||
|
TEST_ASSERT(bytes == 1);
|
||||||
|
|
||||||
|
// 1 byte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1");
|
||||||
|
TEST_ASSERT(bytes == 1);
|
||||||
|
|
||||||
|
// kiB is a wrong unit
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 kiB");
|
||||||
|
TEST_ASSERT(bytes == 1);
|
||||||
|
|
||||||
|
// 1 kibibyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 KiB");
|
||||||
|
TEST_ASSERT(bytes == 1024);
|
||||||
|
|
||||||
|
// 1 mebibyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 MiB");
|
||||||
|
TEST_ASSERT(bytes == 1024*1024);
|
||||||
|
|
||||||
|
// 1 kilobyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 KB");
|
||||||
|
TEST_ASSERT(bytes == 1000);
|
||||||
|
|
||||||
|
// 1 kilobyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 kB");
|
||||||
|
TEST_ASSERT(bytes == 1000);
|
||||||
|
|
||||||
|
// 1 Megabyte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 MB");
|
||||||
|
TEST_ASSERT(bytes == 1000*1000);
|
||||||
|
|
||||||
|
// 1 byte
|
||||||
|
bytes = NLMISC::humanReadableToBytes("1 B");
|
||||||
|
TEST_ASSERT(bytes == 1);
|
||||||
|
|
||||||
|
// not a number
|
||||||
|
bytes = NLMISC::humanReadableToBytes("AB");
|
||||||
|
TEST_ASSERT(bytes == 0);
|
||||||
|
|
||||||
|
// not a positive number
|
||||||
|
bytes = NLMISC::humanReadableToBytes("-1 B");
|
||||||
|
TEST_ASSERT(bytes == 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue