Ejemplo n.º 1
0
void test_string_len() {
    T_ASSERT(RtStrLen("") == 0);
    T_ASSERT(RtStrLen("1") == 1);
    T_ASSERT(RtStrLen("12") == 2);
    T_ASSERT(RtStrLen("123") == 3);
    T_ASSERT(RtStrLen("1234") == 4);
}
Ejemplo n.º 2
0
static void _verify(struct fixture *f, uint64_t byte_b, uint64_t byte_e, uint8_t pat)
{
	struct block *b;
	block_address bb = byte_b / T_BLOCK_SIZE;
	block_address be = (byte_e + T_BLOCK_SIZE - 1) / T_BLOCK_SIZE;
	uint64_t offset = byte_b % T_BLOCK_SIZE;
	uint64_t blen, len = byte_e - byte_b;

	// Verify via bcache_read_bytes
	{
        	unsigned i;
        	size_t len2 = byte_e - byte_b;
		uint8_t *buffer = malloc(len2);
		T_ASSERT(bcache_read_bytes(f->cache, f->fd, byte_b, len2, buffer));
		for (i = 0; i < len; i++)
        		T_ASSERT_EQUAL(buffer[i], _pattern_at(pat, byte_b + i));
        	free(buffer);
	}

	// Verify again, driving bcache directly
	for (; bb != be; bb++) {
        	T_ASSERT(bcache_get(f->cache, f->fd, bb, 0, &b));

		blen = _min(T_BLOCK_SIZE - offset, len);
        	_verify_bytes(b, bb * T_BLOCK_SIZE, offset, blen, pat);

        	offset = 0;
        	len -= blen;

        	bcache_put(b);
	}
}
Ejemplo n.º 3
0
void test_string_cmp() {
    T_ASSERT(RtStrCmp("", "") == 0);
    T_ASSERT(RtStrCmp("1", "1") == 0);
    T_ASSERT(RtStrCmp("1", "2") == -1);
    T_ASSERT(RtStrCmp("1", "12") == -1);
    T_ASSERT(RtStrCmp("12", "1") == 1);
}
Ejemplo n.º 4
0
bool TestPathsEscaping()
{
	std::stringstream stream; 
	stream <<
		"{\n"
			"\"/\": {"
				"\"%v\": 123,\n"
				"\"\\\": 456,\n"
			"},"
		"}\n";

	auto reader = MJson::Reader::Create();

	try {
		MJson::ElementPtr root = reader->Read(stream);

		T_ASSERT(root->Get("\\//%%v")->AsInt() == 123);
		T_ASSERT(root->Get("\\//\\\\")->AsInt() == 456);
	}

	catch(MJson::MJsonException ex)
	{
		std::cerr << ex.what() << std::endl;
		return false;
	}

	return true;
}
Ejemplo n.º 5
0
bool TestBasic()
{
	std::stringstream stream; 
	stream <<
		"{\n"
			"\"dimensions\": {"
				"\"width\": 320,\n"
				"\"height\": 240\n"
			"},"
			"\"tags\": [\"first\", \"second\", \"third\"]\n"
		"}\n";

	auto reader = MJson::Reader::Create();

	try {
		MJson::ElementPtr root = reader->Read(stream);

		T_ASSERT(root->AsDict()["dimensions"]->AsDict()["width"]->AsInt() == 320);
		T_ASSERT(root->AsDict()["dimensions"]->AsDict()["height"]->AsInt() == 240);
		
		T_ASSERT(root->AsDict()["tags"]->AsList()[0]->AsStr() == "first");
		T_ASSERT(root->AsDict()["tags"]->AsList()[1]->AsStr() == "second");
		T_ASSERT(root->AsDict()["tags"]->AsList()[2]->AsStr() == "third");
	}

	catch(MJson::MJsonException ex)
	{
		std::cerr << ex.what() << std::endl;
		return false;
	}

	return true;
}
Ejemplo n.º 6
0
static void _reopen(struct fixture *f)
{
        struct io_engine *engine;

	bcache_destroy(f->cache);
	engine = create_async_io_engine();
	T_ASSERT(engine);

	f->cache = bcache_create(T_BLOCK_SIZE / 512, NR_BLOCKS, engine);
	T_ASSERT(f->cache);
}
Ejemplo n.º 7
0
static void _do_write(struct fixture *f, uint64_t byte_b, uint64_t byte_e, uint8_t pat)
{
        unsigned i;
        size_t len = byte_e - byte_b;
        uint8_t *buffer = malloc(len);
        T_ASSERT(buffer);

        for (i = 0; i < len; i++)
		buffer[i] = _pattern_at(pat, byte_b + i);

        T_ASSERT(bcache_write_bytes(f->cache, f->fd, byte_b, byte_e - byte_b, buffer));
	free(buffer);
}
Ejemplo n.º 8
0
// ==================================================================
action_result_t TActionExecCmd::exec(Tractor * tractor) const
// ==================================================================
{
	T_ASSERT(tractor);

	if (tractor->topActionContext() != getIndex())
	{
		QString cmd(tractor->substituteValues(m_command));

		DEBUG(("Action %d/%s/%d: exec cmd: %s",
		       tractor->getIndex(),
		       qPrintable(tractor->topStation()->getName()),
		       getIndex(), qPrintable(cmd)));

		tractor->pushActionContext(getIndex());
		tractor->exec(getTimeout(), cmd);

		return action_result_pause;
	}

	tractor->popActionContext();

	DEBUG(("Action %d/%s/%d: finished %d", tractor->getIndex(),
	       qPrintable(tractor->topStation()->getName()), getIndex(),
	       tractor->getActionError()));

	if (tractor->getActionError())
	{
		return failure(tractor);
	}

	return action_result_normal;
}
Ejemplo n.º 9
0
void CApplication::setWindowTitle(const CString& title)
{
    m_title = title;

    T_ASSERT(m_window != nullptr);
    m_window->setTitle(m_title.toCharArray());
}
Ejemplo n.º 10
0
TVector2I CApplication::getCursorPosition() const
{
    T_ASSERT(m_window != nullptr);

    sf::Vector2i pos = sf::Mouse::getPosition(*m_window);
    return TVector2I(pos.x, pos.y);
}
Ejemplo n.º 11
0
Archivo: t_auto.c Proyecto: gkmail/tea
T_ID
t_auto_add_edge_data(T_Auto *aut, T_AutoEdge *e)
{
	T_ASSERT(aut && e);

	return edge_array_add(aut, e);
}
Ejemplo n.º 12
0
void CHUD_FPS::update()
{
    T_ASSERT(m_buffer != nullptr);

    const float fps = CApplication::getApp()->getFPS();

    m_buffer->clear();

    m_buffer->addRectangle(m_rec, CColor(127, 127, 127, 127));


    // Texte
    TTextParams params;
    params.text  = CString("FPS : ") + CString::fromNumber(fps);
    params.font  = Game::fontManager->getFontId("Arial");
    params.size  = 16;
    params.color = CColor::White;
    params.rec.setX(m_rec.getX() + 5);
    params.rec.setY(m_rec.getY() + 5);
    params.rec.setWidth(m_rec.getWidth());
    params.rec.setHeight(m_rec.getHeight());

    Game::fontManager->drawText(m_buffer, params);


    m_buffer->update();
}
Ejemplo n.º 13
0
Archivo: t_auto.c Proyecto: gkmail/tea
T_ID
t_auto_add_state_data(T_Auto *aut, T_AutoState *s)
{
	T_ASSERT(aut && s);

	return state_array_add(aut, s);
}
Ejemplo n.º 14
0
// ==================================================================
action_result_t TActionReturn::exec(Tractor * tractor) const
// ==================================================================
{
	T_ASSERT(tractor);

	// same as action_failure_type_return handling
	tractor->popStation();
	return action_result_station_update;
}
Ejemplo n.º 15
0
void ISpinBox::setWidth(int width)
{
    if (width < 0)
        return;

    T_ASSERT(m_line != nullptr);
    T_ASSERT(m_buttonUp != nullptr);
    T_ASSERT(m_buttonDown != nullptr);

         if (width < m_minWidth) m_width = m_minWidth;
    else if (width > m_maxWidth) m_width = m_maxWidth;
    else                         m_width = width;

    m_line->setWidth(m_width - SpinBoxButtonWidth);
    const unsigned int tmpw = m_line->getWidth() - 1;
    m_buttonUp->setX(tmpw);
    m_buttonDown->setX(tmpw);
}
Ejemplo n.º 16
0
// ==================================================================
action_result_t TActionFailure::exec(Tractor * tractor) const
// ==================================================================
{
	FATAL(("TActionFailure::exec() shouldn't be used directly"));
	T_ASSERT(false);

	T_UNUSED(tractor);
	return action_result_abort;
}
Ejemplo n.º 17
0
// ==================================================================
action_result_t TActionRegExp::exec(Tractor *tractor) const
// ==================================================================
{
	T_ASSERT(tractor);
	T_ASSERT(m_data.size());
	T_ASSERT(m_regexp.size());

	QString text(tractor->substituteValues(m_data));
	QStringList assign(m_assignto.split(",", QString::SkipEmptyParts));
	QStringList::const_iterator iter(assign.constBegin());

	QRegExp regexp(m_regexp);
	if (m_case_sensitive)
	{
		regexp.setCaseSensitivity(Qt::CaseSensitive);
	}
	else
	{
		regexp.setCaseSensitivity(Qt::CaseInsensitive);
	}

	if (m_minimal)
	{
		regexp.setMinimal(true);
	}

	int pos(text.indexOf(regexp));

	if (m_strict && pos < 0)
	{
		TERROR(("strict RegExp did not match"));
		return failure(tractor);
	}

	while (pos >= 0 && iter != assign.constEnd())
	{
		tractor->setValue(*iter, regexp.cap(1), m_global);
		pos += regexp.matchedLength();
		pos = text.indexOf(regexp, pos);
		++iter;
	}

	return action_result_normal;
}
Ejemplo n.º 18
0
static struct dm_regex *make_scanner(struct dm_pool *mem, const char **rx)
{
	struct dm_regex *scanner;
	int nrx = 0;
	for (; rx[nrx]; ++nrx);

	scanner = dm_regex_create(mem, rx, nrx);
	T_ASSERT(scanner != NULL);
	return scanner;
}
Ejemplo n.º 19
0
void CApplication::showMouseCursor(bool show)
{
    T_ASSERT(m_window != nullptr);

    m_cursorVisible = show;
    m_cursorPos.X = getWidth() / 2;
    m_cursorPos.Y = getHeight() / 2;

    sf::Mouse::setPosition(sf::Vector2i(m_cursorPos.X, m_cursorPos.Y), *m_window);
}
Ejemplo n.º 20
0
// ==================================================================
action_result_t TActionAssign::exec(Tractor *tractor) const
// ==================================================================
{
	T_ASSERT(tractor);

	const QString substituted = tractor->substituteValues(m_value,
	             (m_last_param.size() > 0 ? &m_last_param : NULL));
	tractor->setValue(m_param, substituted, m_global);
	return action_result_normal;
}
Ejemplo n.º 21
0
void ISpinBox::draw()
{
    T_ASSERT(m_line != nullptr);
    T_ASSERT(m_buttonUp != nullptr);
    T_ASSERT(m_buttonDown != nullptr);

    const unsigned int time = getElapsedTime();
    unsigned int frameTime = time - m_timeLast;
    m_timeLast = time;

    if (m_buttonUp->isDown())
    {
        while (frameTime >= m_timeRepeat)
        {
            frameTime -= m_timeRepeat;
            m_timeRepeat = SpinBoxTimeRepeat;
            stepUp();
        }

        m_timeRepeat -= frameTime;
    }
    else if (m_buttonDown->isDown())
    {
        while (frameTime >= m_timeRepeat)
        {
            frameTime -= m_timeRepeat;
            m_timeRepeat = SpinBoxTimeRepeat;
            stepDown();
        }

        m_timeRepeat -= frameTime;
    }
    else
    {
        m_timeRepeat = SpinBoxTimeBeforeRepeat;
    }

    // Affichage des widgets
    m_line->draw();
    m_buttonUp->draw();
    m_buttonDown->draw();
}
Ejemplo n.º 22
0
Archivo: t_auto.c Proyecto: gkmail/tea
T_ID
t_auto_add_state(T_Auto *aut, T_AutoData data)
{
	T_AutoState s;

	T_ASSERT(aut);

	s.data  = data;
	s.edges = -1;

	return state_array_add(aut, &s);
}
Ejemplo n.º 23
0
static void *_fix_init(struct io_engine *engine)
{
        uint8_t buffer[T_BLOCK_SIZE];
        struct fixture *f = malloc(sizeof(*f));
        unsigned b, i;
	struct statvfs fsdata;
	static int _runs_is_tmpfs = -1;

	if (_runs_is_tmpfs == -1) {
		// With testing in tmpfs directory O_DIRECT cannot be used
		// tmpfs has  f_fsid == 0  (unsure if this is best guess)
		_runs_is_tmpfs = (statvfs(".", &fsdata) == 0 && !fsdata.f_fsid) ? 1 : 0;
		if (_runs_is_tmpfs)
			printf("  Running test in tmpfs, *NOT* using O_DIRECT\n");
	}

        T_ASSERT(f);

        snprintf(f->fname, sizeof(f->fname), "unit-test-XXXXXX");
	f->fd = mkstemp(f->fname);
	T_ASSERT(f->fd >= 0);

	for (b = 0; b < NR_BLOCKS; b++) {
        	for (i = 0; i < sizeof(buffer); i++)
                	buffer[i] = _pattern_at(INIT_PATTERN, byte(b, i));
		T_ASSERT(write(f->fd, buffer, T_BLOCK_SIZE) > 0);
	}

	if (!_runs_is_tmpfs) {
		close(f->fd);
		// reopen with O_DIRECT
		f->fd = open(f->fname, O_RDWR | O_DIRECT);
		T_ASSERT(f->fd >= 0);
	}

	f->cache = bcache_create(T_BLOCK_SIZE / 512, NR_BLOCKS, engine);
	T_ASSERT(f->cache);

        return f;
}
Ejemplo n.º 24
0
} T_END_TEST

T_TEST(t_pqueue_alt_insert) {
	struct pqueue* q = pqueue_create(comp);
	int i;
	int num = 10;

	T_ASSERT(q);

	for (i = 0; i < num; i++) {
		T_ASSERT(0 == pqueue_insert(q, (void*)((i % 2) ? i : num - i - (num % 2 ? 1 : 2))));
	}
	
	T_ASSERT(!pqueue_is_empty(q));

	i = 0;
	while (!pqueue_is_empty(q)) {
		T_ASSERT(i == (int)pqueue_peek(q));
		T_ASSERT(i == (int)pqueue_pop(q));
		i++;
	}

	T_ASSERT(i == num);

	pqueue_destroy(q);
} T_END_TEST
Ejemplo n.º 25
0
/*
 * A little utility which can send single commands to a destination.
 * Special care must be taken in order not to disturb unrelated systems
 * by sending messages to wrong subject area. Presently the destination string
 * must contain /spymon somewhere for simplicity. The default values for command
 * and destination are 'Resume' and '/spymon/command/...' respectively. It is the
 * resposbility of the receiver of the messages to setup proper callbacks to handle
 * the messages.
 */
int main(int argc, char *argv[])
{
    T_IPC_MT mt;
    T_IPC_MSG msg;
    char commStr[20];
    char dest[255];
    char configFile[256];
    char *configDir = 0;

    strcpy(commStr, "Resume");
    strcpy(dest, "/spymon/command/...");
    if (argc < 2) {
        printf("No argument specified! using default:\n");
        printf("-> %s %s %s\n", argv[0], commStr, dest);
    }
    if (argc > 1) strcpy(commStr, argv[1]);
    if (argc > 2) strcpy(dest, argv[2]);

    if (!strstr(dest, "/spymon")) {
        printf("Can only send messaged to subject areas within /spymon\n");
        exit(1);
    }
    /* Set the name of the project */
    configDir = getenv("SMARTSOCKETS_CONFIG_DIR");
    sprintf(configFile, "%s/vxworks.cm", configDir);
    TutCommandParseFile(configFile);

    /* Connect to RTserver */
    if (!TipcSrvCreate(T_IPC_SRV_CONN_FULL)) {
        fprintf(stderr, "Could not connect to RTserver!\n");
        exit(T_EXIT_FAILURE);
    }

    mt  = TipcMtLookupByNum(T_MT_CONTROL);
    msg = TipcMsgCreate(mt);
    T_ASSERT(msg != NULL);
    TipcMsgSetNumFields(msg, 0);
    TipcMsgAppendStr(msg, commStr);
    TipcMsgSetDest(msg, dest);

#if 0
    TipcMsgPrint(msg, TutOut);
#endif
    TipcSrvMsgSend(msg, TRUE);
    TipcSrvFlush();
    TipcMsgDestroy(msg);

    /* Shutdown connection once back from the loop */
    TipcSrvDestroy(T_IPC_SRV_CONN_NONE);

    return TRUE;
}
Ejemplo n.º 26
0
bool TestPaths()
{
	std::stringstream stream; 
	stream <<
		"{\n"
			"\"dimensions\": {"
				"\"width\": 320,\n"
				"\"height\": 240\n"
			"},"
			"\"tags\": [\"first\", \"second\", \"third\"]\n"
		"}\n";

	auto reader = MJson::Reader::Create();

	try {
		MJson::ElementPtr root = reader->Read(stream);

		T_ASSERT(root->Get("dimensions/width")->AsInt() == 320);
		T_ASSERT(root->Get("dimensions/height")->AsInt() == 240);

		int nTags = root->Get("tags")->AsList().size();

		T_ASSERT(nTags == 3);

		std::vector<std::string> expected = {"first", "second", "third"};

		for(int i = 0; i < nTags; i++){
			T_ASSERT(root->Get("tags/%v", {i})->AsStr() == expected[i]); 
		}
	}

	catch(MJson::MJsonException ex)
	{
		std::cerr << ex.what() << std::endl;
		return false;
	}

	return true;
}
Ejemplo n.º 27
0
// ==================================================================
action_result_t TActionStop::exec(Tractor * tractor) const
// ==================================================================
{
	T_ASSERT(tractor);

	// same as action_failure_type_stop handling
	while (tractor->topStation())
	{
		tractor->popStation();
	}

	return action_result_station_update;
}
Ejemplo n.º 28
0
static void _verify_set(struct fixture *f, uint64_t byte_b, uint64_t byte_e, uint8_t val)
{
        unsigned i;
	struct block *b;
	block_address bb = byte_b / T_BLOCK_SIZE;
	block_address be = (byte_e + T_BLOCK_SIZE - 1) / T_BLOCK_SIZE;
	uint64_t offset = byte_b % T_BLOCK_SIZE;
	uint64_t blen, len = byte_e - byte_b;

	for (; bb != be; bb++) {
        	T_ASSERT(bcache_get(f->cache, f->fd, bb, 0, &b));

		blen = _min(T_BLOCK_SIZE - offset, len);
		for (i = 0; i < blen; i++)
        		T_ASSERT(((uint8_t *) b->data)[offset + i] == val);

        	offset = 0;
        	len -= blen;

        	bcache_put(b);
	}
}
Ejemplo n.º 29
0
ISpinBox::ISpinBox(IWidget * parent) :
IWidget       (parent),
m_timeLast   (getElapsedTime()),
m_timeRepeat (SpinBoxTimeBeforeRepeat),
m_wrapping    (true),
m_prefix      (),
m_suffix      (),
m_line        (nullptr),
m_buttonUp      (nullptr),
m_buttonDown    (nullptr)
{
    m_line = new CLineEdit(this);
    T_ASSERT(m_line != nullptr);

    int minh = m_line->getMinHeight() / 2;
    int maxh = m_line->getMaxHeight();

    // Boutons
    m_buttonUp = new CPushButton("+", this);
    T_ASSERT(m_buttonUp != nullptr);

    m_buttonUp->setX(m_line->getWidth());
    m_buttonUp->setMinSize(SpinBoxButtonWidth, minh);
    m_buttonUp->setMaxSize(SpinBoxButtonWidth, maxh / 2);
    m_buttonUp->onClicked.connect(sigc::mem_fun(this, &ISpinBox::stepUp));

    m_buttonDown = new CPushButton("-", this);
    T_ASSERT(m_buttonDown != nullptr);

    m_buttonDown->setPosition(m_line->getWidth() - 1, minh);
    m_buttonDown->setMinSize(SpinBoxButtonWidth, minh);
    m_buttonDown->setMaxSize(SpinBoxButtonWidth, maxh / 2);
    m_buttonDown->onClicked.connect(sigc::mem_fun(this, &ISpinBox::stepDown));

    m_line->onTextChange.connect(sigc::mem_fun(this, &ISpinBox::updateValue));

    setMaxHeight(maxh);
}
Ejemplo n.º 30
0
void COctree::Divide(const TVector3F& center)
{
    m_center = center;

    if (m_child[0] == nullptr)
    {
        // Création des nœuds enfant
        for (int i = 0; i < 8; ++i)
        {
            m_child[i] = new COctree();
            T_ASSERT(m_child[i] != nullptr);
        }
    }
}