2012-10-08 14:53:43 -04:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2012 Anthony Pesce
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "TestBase.h"
|
2012-10-16 13:57:00 -04:00
|
|
|
|
2012-10-08 14:53:43 -04:00
|
|
|
#include "common/Shaker.h"
|
|
|
|
|
|
2012-10-16 13:57:00 -04:00
|
|
|
using namespace std;
|
|
|
|
|
|
2012-10-08 14:53:43 -04:00
|
|
|
class Shakertest : public Cyphesis::TestBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Shaker * m_shaker;
|
|
|
|
|
public:
|
|
|
|
|
Shakertest();
|
|
|
|
|
void setup();
|
|
|
|
|
void teardown();
|
2012-10-16 13:57:00 -04:00
|
|
|
void testGenerate();
|
2012-10-08 14:53:43 -04:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Shakertest::Shakertest()
|
|
|
|
|
{
|
2012-10-16 13:57:00 -04:00
|
|
|
ADD_TEST(Shakertest::testGenerate);
|
2012-10-08 14:53:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Shakertest::setup()
|
|
|
|
|
{
|
2012-10-08 19:54:41 -04:00
|
|
|
m_shaker = new Shaker;
|
2012-10-08 14:53:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Shakertest::teardown()
|
|
|
|
|
{
|
2012-10-08 19:54:41 -04:00
|
|
|
delete m_shaker;
|
2012-10-08 14:53:43 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 13:57:00 -04:00
|
|
|
void Shakertest::testGenerate()
|
2012-10-08 14:53:43 -04:00
|
|
|
{
|
2012-10-16 13:57:00 -04:00
|
|
|
unsigned int salt_length1 = 0;
|
|
|
|
|
unsigned int salt_length2 = 8;
|
|
|
|
|
unsigned int salt_length3 = 100;
|
|
|
|
|
std::string s1 = m_shaker->generateSalt(salt_length1);
|
|
|
|
|
ASSERT_NOT_NULL(&s1);
|
|
|
|
|
ASSERT_TRUE(salt_length1*2==s1.length());
|
|
|
|
|
for(unsigned int i =0;i<s1.length();i++)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_TRUE(isxdigit(s1[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string s2 = m_shaker->generateSalt(salt_length2);
|
|
|
|
|
ASSERT_NOT_NULL(&s2);
|
|
|
|
|
ASSERT_TRUE(salt_length2*2==s2.length());
|
|
|
|
|
for(unsigned int i =0;i<s2.length();i++)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_TRUE(isxdigit(s2[i]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string s3 = m_shaker->generateSalt(salt_length3);
|
|
|
|
|
ASSERT_NOT_NULL(&s3);
|
|
|
|
|
ASSERT_TRUE(salt_length3*2==s3.length());
|
|
|
|
|
for(unsigned int i =0;i<s3.length();i++)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_TRUE(isxdigit(s3[i]));
|
|
|
|
|
}
|
2012-10-08 14:53:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2012-10-08 19:54:41 -04:00
|
|
|
Shakertest t;
|
2012-10-08 14:53:43 -04:00
|
|
|
|
2012-10-08 19:54:41 -04:00
|
|
|
return t.run();
|
2012-10-08 14:53:43 -04:00
|
|
|
}
|