Пример #1
0
void ebnf_start_parsing__declaration() {
    FsmCursor cur;

    //Fake main nonterminal
    fsm_cursor_init(&cur, &fix.fsm);
    fsm_cursor_define(&cur, nzs("non_terminal_declaration"));
    fsm_cursor_done(&cur, '\0');

    Action *action;
    int E_NON_TERMINAL_DECLARATION = fsm_get_symbol(&fix.fsm, nzs("non_terminal_declaration"));

    Session session;
    session_init(&session, &fix.fsm);
    MATCH(session, L_IDENTIFIER);
    MATCH(session, L_DEFINING_SYMBOL);
    MATCH(session, L_TERMINAL_STRING);
    MATCH(session, L_DEFINITION_SEPARATOR_SYMBOL);
    MATCH(session, L_IDENTIFIER);
    MATCH(session, L_TERMINATOR_SYMBOL);

    action = TEST(session, L_EOF);
    t_assert(action->type == ACTION_REDUCE);
    t_assert(action->reduction == E_NON_TERMINAL_DECLARATION);

    MATCH(session, L_EOF);
    t_assert(session.current->type == ACTION_ACCEPT);

    session_dispose(&session);
    fsm_cursor_dispose(&cur);
}
Пример #2
0
Float::Float(QWidget *parent, HistoryItem *item, base::lambda<void(bool visible)> toggleCallback, base::lambda<void(bool closed)> draggedCallback) : TWidget(parent)
, _item(item)
, _toggleCallback(std::move(toggleCallback))
, _draggedCallback(std::move(draggedCallback)) {
	auto media = _item->getMedia();
	t_assert(media != nullptr);

	auto document = media->getDocument();
	t_assert(document != nullptr);
	t_assert(document->isRoundVideo());

	auto margin = st::mediaPlayerFloatMargin;
	auto size = 2 * margin + st::mediaPlayerFloatSize;
	resize(size, size);

	prepareShadow();

	subscribe(Global::RefItemRemoved(), [this](HistoryItem *item) {
		if (_item == item) {
			detach();
		}
	});

	setCursor(style::cur_pointer);
}
void ConnectorTest::makeSocketWithReuseTest()
{
	// connect to http server on localhost
	Connector connector(GetConfig()["SocketConnectSuccessHost"]["ip"].AsString(), GetConfig()["SocketConnectSuccessHost"]["port"].AsLong(), 0L, String(), 0L, true);

	// assert the internal state
	assertEqual( GetConfig()["SocketConnectSuccessHost"]["ip"].AsString(), connector.GetAddress() );
	assertEqual( GetConfig()["SocketConnectSuccessHost"]["port"].AsLong(), connector.fPort );
	assertEqual( (long)NULL, (long)connector.fSocket );

	// check basic functionality
	Socket *s1 = connector.MakeSocket(false);
	Socket *s2 = connector.MakeSocket(false);

	long sock1 = 0, sock2 = 0;

	if (s1 != 0) {
		sock1 = s1->GetFd();
		t_assert( s1 != NULL );
		if (s2 != 0) {
			t_assert( s1 != s2 );
		} // if
		delete s1;
		assertEqual( 0L, ::closeSocket(sock1));
	}

	if (s2 != 0) {
		sock2 = s2->GetFd();

		t_assert( s2 != NULL );
		delete s2;
		// should not result in an error because destructor has not closed socket
		assertEqual( 0L, ::closeSocket(sock2));
	}
} // makeSocketTest
void ConnectorTest::ConnectAndAssert(const char *host, long port, long timeout, bool threadLocal, bool shouldFail)
{
	Connector connector(host, port, timeout, String(), 0L, threadLocal);

	// assert the internal state of the connector
	assertEqual( port, connector.fPort );
	assertEqual( timeout, connector.fConnectTimeout );
	assertEqual( (long)NULL, (long)connector.fSocket );

	// assert the funtionality of the public api
	String assertMsg(host);
	assertMsg << ":" << port << " with timeout: " << timeout;
	String realMsg(assertMsg);
	realMsg << (( connector.Use() ) ? " has not failed" : " has failed");
	if ( shouldFail ) {
		assertMsg << " has failed";
		assertEqual(assertMsg, realMsg);
		t_assert( connector.Use() == NULL );
		t_assert( connector.GetStream() == NULL );
	} else {
		assertMsg << " has not failed";
		assertEqual(assertMsg, realMsg);
		t_assert( connector.Use() != NULL );
		t_assert( connector.GetStream() != NULL );
	}
}
Пример #5
0
void ebnf_start_parsing__group() {
    FsmCursor cur;

    //Fake main nonterminal
    fsm_cursor_init(&cur, &fix.fsm);
    fsm_cursor_define(&cur, nzs("expression"));
    fsm_cursor_done(&cur, '\0');

    Action *action;
    int E_EXPRESSION = fsm_get_symbol(&fix.fsm, nzs("expression"));

    Session session;
    session_init(&session, &fix.fsm);
    MATCH(session, L_START_GROUP_SYMBOL);
    MATCH(session, L_TERMINAL_STRING);
    MATCH(session, L_END_GROUP_SYMBOL);

    action = TEST(session, L_TERMINATOR_SYMBOL);
    t_assert(action->type == ACTION_REDUCE);
    t_assert(action->reduction == E_EXPRESSION);

    MATCH(session, L_TERMINATOR_SYMBOL);
    t_assert(session.current->type == ACTION_ACCEPT);

    session_dispose(&session);
    fsm_cursor_dispose(&cur);
}
void WorkerPoolManagerTest::EnterLeaveTests() {
	StartTrace(WorkerPoolManagerTest.EnterLeaveTests);
	const long cPoolSz = 2;
	SamplePoolManager wpm("EnterLeaveTestsPool");
	Anything config;
	config["timeout"] = 1;
	config["test"] = Anything((IFAObject *) this);
	t_assert(wpm.Init(cPoolSz, 0, 0, 0, ROAnything(config)) == 0);
	t_assert(wpm.GetPoolSize() == cPoolSz);
	t_assert(wpm.ResourcesUsed() == 0);

	Anything work;
	for (long i = 0; i < 2 * cPoolSz; i++) {
		wpm.Enter(ROAnything(work), -1L);
	}
	t_assert(wpm.AwaitEmpty(5));
	t_assert(wpm.Terminate());

	Anything expected;
	Anything statistic;
	wpm.Statistic(statistic);
	expected["PoolSize"] = 2;
	expected["CurrentParallelRequests"] = 0;
	expected["MaxParallelRequests"] = 2;
	expected["TotalRequests"] = 4;
	statistic.Remove("TotalTime [ms]"); // since varies
	statistic.Remove("AverageTime [ms]"); // since varies
	statistic.Remove("TRX/sec"); // since varies

	assertAnyEqualm(expected, statistic, "statistic differs");
}
void TransitionTests::PBOWBookmarkSequence()
//: simulate a privileged bookmark with a subsequent successful login
//  privileged request -> PBOWLoginPage ...
//  successful login request -> PBOWCustomerOnlyPage2 (now in privileged role) ...
//  logout request -> PBOWLoginPage (back to unprivileged role)
{
	Anything r1, r2, r3;
	// the session is back in unprivileged mode (or has even been removed)...
	// re-play a privileged request:

	t_assert(EvalRequest(fBookmarkedRequest, r1));
	assertEqual("PBOWLoginPage", r1["page"].AsString());	// login must be enforced

	// -- perform successful login using existing session id...
	//    original request should be satisfied...
	Anything c1 = AddSessionInfo(GetConfig()["GoodLoginRequest"], r1);
	t_assert(EvalRequest(c1, r2));
	assertEqual("PBOWCustomerOnlyPage2", r2["page"].AsString());

	// verify if we are still using the same session
	assertEqual(r1["sessionId"].AsString(), r2["sessionId"].AsString());

	// -- logout (overwrite r3)
	Anything c3 = AddSessionInfo(GetConfig()["LogoutRequest"], r3);
	t_assert(EvalRequest(c3, r3));
	assertEqual("PBOWLoginPage", r3["page"].AsString());
}
void TransitionTests::RunRequestSequence()
{
	// startup a simple server
	Server *server = Server::FindServer("PBOWTypeServer");
	if ( t_assert(server != 0) ) {
		ServerThread mt(server);
		if ( t_assert(mt.Start()) && t_assert(mt.CheckState(Thread::eRunning, 5)) ) {
			if ( t_assertm(mt.serverIsInitialized(), "expected initialization to succeed") ) {
				mt.SetWorking();
				if (t_assertm(mt.IsReady(true, 5), "expected server to become ready within 5 seconds")) {
					// --- run various request sequences
					PBOWLoginSequence1();
					PBOWLoginSequence2();
					PBOWFailedBookmarkSequence();
					PBOWBookmarkSequence();
					mt.PrepareShutdown(0);
				}
			}
			if (t_assertm(mt.IsReady(false, 5), "expected server to become terminated within 5 seconds")) {
				mt.Terminate(10);
			}
		}
		t_assertm(mt.CheckState(Thread::eTerminated, 10), "expected server thread to become terminated");
	}
}
Пример #9
0
bool TaskQueue::TaskQueueList::Empty(int list_index_) const {
	t_assert(list_index_ < kQueuesListsCount);

	auto list = lists_[list_index_];
	t_assert(list != nullptr);
	return (list->list_entries_[list_index_].after == nullptr);
}
Пример #10
0
void paintUnreadBadge(Painter &p, const QRect &rect, const UnreadBadgeStyle &st) {
	t_assert(rect.height() == st.size);

	int index = (st.muted ? 0x03 : 0x00) + (st.active ? 0x02 : (st.selected ? 0x01 : 0x00));
	int size = st.size, sizehalf = size / 2;

	unreadBadgeStyle.createIfNull();
	auto badgeData = unreadBadgeStyle->sizes;
	if (st.sizeId > 0) {
		t_assert(st.sizeId < UnreadBadgeSizesCount);
		badgeData = &unreadBadgeStyle->sizes[st.sizeId];
	}
	auto bg = unreadBadgeStyle->bg[index];
	if (badgeData->left[index].isNull()) {
		int imgsize = size * cIntRetinaFactor(), imgsizehalf = sizehalf * cIntRetinaFactor();
		createCircleMask(badgeData, size);
		badgeData->left[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, 0, bg));
		badgeData->right[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, imgsize - imgsizehalf, bg));
	}

	int bar = rect.width() - 2 * sizehalf;
	p.drawPixmap(rect.x(), rect.y(), badgeData->left[index]);
	if (bar) {
		p.fillRect(rect.x() + sizehalf, rect.y(), bar, rect.height(), bg);
	}
	p.drawPixmap(rect.x() + sizehalf + bar, rect.y(), badgeData->right[index]);
}
Пример #11
0
void ServerTest::InitRunResetRunTerminateAcceptorTest() {
	StartTrace(ServerTest.InitRunResetRunTerminateAcceptorTest);
	TestCaseType::DoUnloadConfig();
	for (long i = 0; i < 3; i++) {
		TestCaseType::DoLoadConfig("ServerTest", "InitRunResetRunTerminateAcceptorTest");
		Server *server = Server::FindServer("AcceptorWorkerServer");
		if (t_assertm(server != NULL, "expected AcceptorsWorkersServer to be there")) {
			server = (Server *) server->ConfiguredClone("Server", "AcceptorWorkerServerMaster", true);
			if (t_assertm(server != NULL, "expected server-clone to succeed")) {
				ServerThread mt(server);
				if (t_assert(mt.Start()) && t_assert(mt.CheckState(Thread::eRunning, 5))) {
					if (t_assertm(mt.serverIsInitialized(), "expected initialization to succeed")) {
						mt.SetWorking();
						if (t_assertm(mt.IsReady(true, 5), "expected server to become ready within 5 seconds")) {
							// --- run various request
							//     sequences
							RunTestSequence();
							if (t_assertm(server->GlobalReinit() == 0, "expected server to reinit ok")) {
								RunTestSequence();
							}
							mt.PrepareShutdown(0);
						}
					}
					if (t_assertm(mt.IsReady(false, 5), "expected server to become terminated within 5 seconds")) {
						mt.Terminate(10);
					}
				}
				mt.CheckState(Thread::eTerminated, 5);
				server->Finalize();
				delete server;
			}
		}
		TestCaseType::DoUnloadConfig();
	}
}
Пример #12
0
void PlayButtonLayout::paint(Painter &p, const QBrush &brush) {
	if (_transformProgress.animating(getms())) {
		auto from = _oldState, to = _state;
		auto backward = _transformBackward;
		auto progress = _transformProgress.current(1.);
		if (from == State::Cancel || (from == State::Pause && to == State::Play)) {
			qSwap(from, to);
			backward = !backward;
		}
		if (backward) progress = 1. - progress;

		t_assert(from != to);
		if (from == State::Play) {
			if (to == State::Pause) {
				paintPlayToPause(p, brush, progress);
			} else {
				t_assert(to == State::Cancel);
				paintPlayToCancel(p, brush, progress);
			}
		} else {
			t_assert(from == State::Pause && to == State::Cancel);
			paintPauseToCancel(p, brush, progress);
		}
	} else {
		switch (_state) {
		case State::Play: paintPlay(p, brush); break;
		case State::Pause: paintPlayToPause(p, brush, 1.); break;
		case State::Cancel: paintPlayToCancel(p, brush, 1.); break;
		}
	}
}
Пример #13
0
void AudioPlayerLoader::takeSavedDecodedSamples(QByteArray *samples, int64 *samplesCount) {
	t_assert(*samplesCount == 0);
	t_assert(samples->isEmpty());
	t_assert(_holdsSavedSamples);
	samples->swap(_savedSamples);
	std::swap(*samplesCount, _savedSamplesCount);
	_holdsSavedSamples = false;
}
Пример #14
0
void AudioPlayerLoader::saveDecodedSamples(QByteArray *samples, int64 *samplesCount) {
	t_assert(_savedSamplesCount == 0);
	t_assert(_savedSamples.isEmpty());
	t_assert(!_holdsSavedSamples);
	samples->swap(_savedSamples);
	std::swap(*samplesCount, _savedSamplesCount);
	_holdsSavedSamples = true;
}
Пример #15
0
void ServerTest::setUp() {
	StartTrace(ServerTest.setUp);
	t_assert(GetConfig().IsDefined("Modules"));
	Server *s;
	if (t_assert((s = Server::FindServer("Server")) != NULL)) {
		ROAnything result;
		t_assert(s->Lookup("TCP5010", result));
		TraceAny(result, "server lookup TCP5010");
	}
}
Пример #16
0
void int_to_array__one_byte(){

	int symbol = 40;
	unsigned char buffer[sizeof(int)];
	unsigned int size;

	int_to_array(buffer, &size, symbol);

	t_assert(size == 1);
	t_assert(buffer[0] == 40);
}
Пример #17
0
void int_to_array__negative(){

	int symbol = -1;
	unsigned char buffer[sizeof(int)];
	unsigned int size;

	int_to_array(buffer, &size, symbol);

	t_assert(size == sizeof(int));
	t_assert(buffer[0] == 0xFF);
}
Пример #18
0
void ast_empty(){
	AstCursor cursor;
	AstNode *node;

	ast_cursor_init(&cursor, &fix.ast);
	node = ast_cursor_depth_next(&cursor);
	t_assert(node != NULL);
	node = ast_cursor_depth_next(&cursor);
	t_assert(node == NULL);

	ast_cursor_dispose(&cursor);
}
Пример #19
0
void int_to_array__two_bytes(){

	int symbol = 258;
	unsigned char buffer[sizeof(int)];
	unsigned int size;

	int_to_array(buffer, &size, symbol);

	t_assert(size == 2);
	t_assert(buffer[0] == 2);
	t_assert(buffer[1] == 1);
}
Пример #20
0
void SocketTest::simpleConstructorTest() {
	Connector connector(GetConfig()["SocketConnectSuccessHost"]["ip"].AsString(), GetConfig()["SocketConnectSuccessHost"]["port"].AsLong());
	Socket *socket = connector.MakeSocket(); //lint !e578

	if (t_assertm( socket != NULL, (const char *)connector.GetAddress() )) {
		long socketfd = socket->GetFd();
		t_assert( socketfd > 0);

		std::iostream *Ios = socket->GetStream();
		t_assert( Ios != NULL);
	}
	delete socket;
}
Пример #21
0
QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInlineBotUsername) const {
	t_assert(outInlineBot != nullptr);
	t_assert(outInlineBotUsername != nullptr);

	const QString &text(getLastText());

	int32 inlineUsernameStart = 1, inlineUsernameLength = 0, size = text.size();
	if (size > 2 && text.at(0) == '@' && text.at(1).isLetter()) {
		inlineUsernameLength = 1;
		for (int32 i = inlineUsernameStart + 1, l = text.size(); i < l; ++i) {
			if (text.at(i).isLetterOrNumber() || text.at(i).unicode() == '_') {
				++inlineUsernameLength;
				continue;
			}
			if (!text.at(i).isSpace()) {
				inlineUsernameLength = 0;
			}
			break;
		}
		if (inlineUsernameLength && inlineUsernameStart + inlineUsernameLength < text.size() && text.at(inlineUsernameStart + inlineUsernameLength).isSpace()) {
			QStringRef username = text.midRef(inlineUsernameStart, inlineUsernameLength);
			if (username != *outInlineBotUsername) {
				*outInlineBotUsername = username.toString();
				PeerData *peer = App::peerByName(*outInlineBotUsername);
				if (peer) {
					if (peer->isUser()) {
						*outInlineBot = peer->asUser();
					} else {
						*outInlineBot = nullptr;
					}
				} else {
					*outInlineBot = LookingUpInlineBot;
				}
			}
			if (*outInlineBot == LookingUpInlineBot) return QString();

			if (*outInlineBot && (!(*outInlineBot)->botInfo || (*outInlineBot)->botInfo->inlinePlaceholder.isEmpty())) {
				*outInlineBot = nullptr;
			} else {
				return text.mid(inlineUsernameStart + inlineUsernameLength + 1);
			}
		} else {
			inlineUsernameLength = 0;
		}
	}
	if (inlineUsernameLength < 3) {
		*outInlineBot = nullptr;
		*outInlineBotUsername = QString();
	}
	return QString();
}
//---- NewRendererTest ----------------------------------------------------------------
void NewRendererTest::TestCases() {
	StartTrace(NewRendererTest.TestCases);

	if (t_assertm( !GetTestCaseConfig().IsNull(), "no Tests configured!" )) {
		Server *theServer = Server::FindServer("Server");
		t_assert(theServer != NULL);
		Context ctx;
		Session theSession("TestSession");
		Page *thePage = Page::FindPage("TestPage");
		t_assert(thePage != NULL);
		Role *theRole = Role::FindRole("TestRole");
		t_assert(theRole != NULL);
		theSession.Init("TestSession", ctx);

		AnyExtensions::Iterator<ROAnything, ROAnything, TString> aEntryIterator(GetTestCaseConfig());
		ROAnything roaCaseConfig;
		t_assertm( GetConfig()["RunOnly"].GetSize() == 0L, "running only subset of tests");
		TraceAny(GetConfig()["RunOnly"], "run only config")
		while (aEntryIterator.Next(roaCaseConfig)) {
			TString slotToCheck;
			aEntryIterator.SlotName(slotToCheck);
			Trace("current testslot [" << slotToCheck << "]");
			if ((GetConfig()["RunOnly"].GetSize() == 0L) || GetConfig()["RunOnly"].Contains((const char *) slotToCheck)) {
				std::cerr << ".";
				TString message;
				message << getConfigFileName() << ".any:0 at " << name();
				if (slotToCheck.Length()) {
					message << "." << slotToCheck;
				} else {
					message << ":" << aEntryIterator.Index();
				}
				Context c(GetConfig()["EnvForAllCases"].DeepClone(), roaCaseConfig["Env"].DeepClone(), theServer, &theSession, theRole,
						thePage);
				coast::testframework::PutInStore(roaCaseConfig["TmpStore"], c.GetTmpStore());
				coast::testframework::PutInStore(roaCaseConfig["SessionStore"], c.GetSessionStore());
				TraceAny(roaCaseConfig["Renderer"], "running renderer at [" << slotToCheck << "]");
				String result("[");
				String expected("[");
				expected << roaCaseConfig["Expected"].AsCharPtr("") << "]";
				{
					OStringStream reply(result);
					Renderer::Render(reply, c, roaCaseConfig["Renderer"]);
					reply.flush();
				}
				result.Append(']');
				// message << ":\n" << result;
				assertEqualm(expected, result, message);
			}
		}
	}
Пример #23
0
void TaskQueue::TaskQueueList::Remove(TaskQueue *queue, int list_index_) {
	t_assert(list_index_ < kQueuesListsCount);

	auto &list_entry = queue->list_entries_[list_index_];
	t_assert(list_entry.after != nullptr);
	if (lists_[list_index_] == queue) {
		lists_[list_index_] = list_entry.after;
	} else {
		t_assert(list_entry.before != nullptr);
		list_entry.before->list_entries_[list_index_].after = list_entry.after;
	}
	list_entry.after->list_entries_[list_index_].before = list_entry.before;
	list_entry.before = list_entry.after = nullptr;
}
void HTTPPostRequestBodyParserTest::ReadMultiPartPost()
{
	StartTrace(HTTPPostRequestBodyParserTest.ReadMultiPartPost);
	std::iostream *is = coast::system::OpenStream("MultiPartBody.txt", 0);

	t_assertm(is != 0, "expected 'MultiPartBody.txt' to be there");
	if ( is ) {
		MIMEHeader mh;
		t_assertm(mh.ParseHeaders(*is, 4096, 4096), "expected global header parsing to succeed");
		assertEqual(586L, mh.GetParsedHeaderLength());
		HTTPPostRequestBodyParser sm(mh);
		t_assert(sm.Parse(*is));
		Anything expected;
		Anything result = sm.GetContent();

		delete is;

		t_assert(!GetConfig().IsNull());
		assertAnyEqual(GetConfig()["MultiPartResult"], result);
	}
	// This sequence takes advantage of the String::SubString
	// feature to return the whole remainder of the string starting
	// from the first occurrence the substring-pattern has been found.
	// This relieves us from the need to create an expected result file
	// which we would use to verify the results.

	is =  coast::system::OpenStream("MultiPartBody.txt", 0);
	if ( is ) {
		MIMEHeader mh;
		t_assertm(mh.ParseHeaders(*is, 4096, 4096), "expected global header parsing to succeed");
		assertEqual(586L, mh.GetParsedHeaderLength());
		HTTPPostRequestBodyParser sm(mh);
		t_assert(sm.Parse(*is));
		String unparsedContent = sm.GetUnparsedContent();
		delete is;

		is =  coast::system::OpenStream("MultiPartBody.txt", 0);
		if (is) {
			char c;
			String tmp;
			while ((!!(*is).get(c))) {
				tmp.Append(c);
			}
			String final;
			final = tmp.SubString(unparsedContent);
			assertEqual(final, unparsedContent);
			delete is;
		}
	}
Пример #25
0
static void
t4(void) {
	int		result;
	isc_time_t	expires;
	isc_interval_t	interval;

	t_assert("isc_timer_reset", 4, T_REQUIRED, "%s", a4);

	if (threaded) {
		Tx_nfails = 0;
		Tx_nprobs = 0;
		Tx_nevents = 3;
		Tx_seconds = T4_SECONDS;
		Tx_nanoseconds = T4_NANOSECONDS;

		isc_interval_set(&interval, T4_SECONDS, T4_NANOSECONDS);
		isc_time_settoepoch(&expires);
		t_timers_x(isc_timertype_ticker, &expires, &interval, t4_te);

		result = T_UNRESOLVED;

		if ((Tx_nfails == 0) && (Tx_nprobs == 0))
			result = T_PASS;
		else if (Tx_nfails)
			result = T_FAIL;

		t_result(result);
	} else
		require_threads();
}
Пример #26
0
static void _parse_parent_child_nonterminal(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_child_rule_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Пример #27
0
static void _parse_sibling_with_children_test(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_siblings_with_children(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_parent(&builder);
	ast_builder_append_follow(&builder, &(Token){4, 1, 'd'});
	ast_builder_append(&builder, &(Token){5, 1, 'e'});
	ast_builder_append(&builder, &(Token){6, 1, 'f'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Пример #28
0
void _parser_basic_parse(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_simple_ab_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
Пример #29
0
void destroyShortcut(QShortcut *shortcut) {
	t_assert(DataPtr != nullptr);

	DataPtr->handlers.remove(shortcut->id());
	DataPtr->mediaShortcuts.remove(shortcut);
	delete shortcut;
}
Пример #30
0
static void
test_dns_resolver_settimeout_to_default(void) {
	dns_resolver_t *resolver = NULL;
	int test_result;
	unsigned int default_timeout, timeout;

	t_assert("test_dns_resolver_settimeout_to_default", 1, T_REQUIRED, "%s",
		 "_settimeout() can change the timeout back to a default value"
		 " by specifying 0 as the timeout.");
	setup();
	CHECK(make_resolver(&resolver));

	default_timeout = dns_resolver_gettimeout(resolver);
	t_info("The default timeout is %d second%s\n", default_timeout,
	       (default_timeout == 1 ? "" : "s"));

	dns_resolver_settimeout(resolver, default_timeout - 1);
	timeout = dns_resolver_gettimeout(resolver);
	t_info("The new timeout is %d second%s\n", timeout,
	       (timeout == 1 ? "" : "s"));

	dns_resolver_settimeout(resolver, 0);
	timeout = dns_resolver_gettimeout(resolver);
	test_result = (timeout == default_timeout) ? T_PASS : T_FAIL;

	destroy_resolver(&resolver);
	teardown();

	t_result(test_result);
}