當前位置: 首頁>>代碼示例>>C++>>正文


C++ ASSERT_EXIT函數代碼示例

本文整理匯總了C++中ASSERT_EXIT函數的典型用法代碼示例。如果您正苦於以下問題:C++ ASSERT_EXIT函數的具體用法?C++ ASSERT_EXIT怎麽用?C++ ASSERT_EXIT使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ASSERT_EXIT函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: TEST

TEST(DEATHTEST, snprintf_fortified2) {
  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
  foo myfoo;
  strcpy(myfoo.a, "012345678");
  size_t n = strlen(myfoo.a) + 2;
  ASSERT_EXIT(snprintf(myfoo.b, n, "a%s", myfoo.a), testing::KilledBySignal(SIGABRT), "");
}
開發者ID:MazWoz,項目名稱:platform_bionic,代碼行數:7,代碼來源:fortify_test.cpp

示例2: TEST

TEST(DEATHTEST, strncpy2_fortified) {
  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
  char dest[11];
  char src[10];
  memcpy(src, "0123456789", sizeof(src)); // src is not null terminated
  ASSERT_EXIT(strncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), "");
}
開發者ID:junzhe,項目名稱:platform_bionic,代碼行數:7,代碼來源:fortify_test.cpp

示例3: TEST

// one byte target with longer source (should fail)
TEST(Fortify1_DeathTest, strcpy4_fortified) {
  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
  char buf[1];
  char *orig = strdup("12");
  ASSERT_EXIT(strcpy(buf, orig), testing::KilledBySignal(SIGABRT), "");
  free(orig);
}
開發者ID:AdrianoMartins,項目名稱:bionic,代碼行數:8,代碼來源:fortify1_test.cpp

示例4: TEST

TEST(DEATHTEST, read_fortified) {
  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
  char buf[1];
  size_t ct = atoi("2"); // prevent optimizations
  int fd = open("/dev/null", O_RDONLY);
  ASSERT_EXIT(read(fd, buf, ct), testing::KilledBySignal(SIGABRT), "");
  close(fd);
}
開發者ID:AOSP-S4,項目名稱:platform_bionic,代碼行數:8,代碼來源:fortify_test.cpp

示例5: GetExecutablePathQuoted

void GetExecutablePathQuoted(wchar_t* outpath, int outpath_length)
{
    wchar_t* temppath = new wchar_t[outpath_length];
    GetExecutablePath(temppath, outpath_length);
    int result = swprintf_s(outpath, outpath_length, L"\"%s\"", temppath);
    ASSERT_EXIT((-1 != result), "swprintf_s(outpath)");
    delete[] temppath;
    temppath = 0;
}
開發者ID:KMayne,項目名稱:5minutebreak,代碼行數:9,代碼來源:ExecutablePath.cpp

示例6: GetExecutablePath

void GetExecutablePath(wchar_t* outpath, int outpath_length)
{
    // This path is longer than MAX_PATH, do not use it with
    // windows api functions as you might get buffer overflows.

    wchar_t shortpath[1024];
    wchar_t longpath[1024];

    DWORD dw;

    dw = GetModuleFileName(NULL, shortpath, 1024);
    ASSERT_EXIT(dw, "GetModuleFileName()");

    dw = GetLongPathName(shortpath, longpath, 1024);
    ASSERT_EXIT(dw, "GetLongPathName()");

    swprintf_s(outpath, outpath_length, L"%s", longpath);
}
開發者ID:KMayne,項目名稱:5minutebreak,代碼行數:18,代碼來源:ExecutablePath.cpp

示例7: TEST

TEST(ExampleTests, test_no_death){

    auto a = [] () {
        int a = 0;
        a = 7;
        int b = a;
        a = b;
        exit(0);
    };

    ASSERT_EXIT(a(), ::testing::ExitedWithCode(0), "");
}
開發者ID:Dexter245,項目名稱:gauss_cpp,代碼行數:12,代碼來源:test_examples.cpp

示例8: TEST_F

TEST_F(properties_DeathTest, read_only) {
#if defined(__BIONIC__)

  // This test only makes sense if we're talking to the real system property service.
  struct stat sb;
  if (stat(PROP_FILENAME, &sb) == -1 && errno == ENOENT) {
    return;
  }

  ASSERT_EXIT(__system_property_add("property", 8, "value", 5), KilledByFault(), "");
#else // __BIONIC__
  GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif // __BIONIC__
}
開發者ID:Decatf,項目名稱:platform_bionic,代碼行數:14,代碼來源:system_properties_test.cpp

示例9: GetExecutableName

void GetExecutableName(wchar_t* outdir, int outdir_length)
{
    // Filename without extension.

    wchar_t longpath[1024];
    GetExecutablePath(longpath, _countof(longpath));

    wchar_t drive[3];
    wchar_t dir[768];
    wchar_t fname[256];
    wchar_t ext[32];

    errno_t result = _wsplitpath_s(longpath, drive, _countof(drive), dir, _countof(dir), fname, _countof(fname), ext, _countof(ext));
    ASSERT_EXIT((result == 0), "_wsplitpath_s(longpath)");

    swprintf_s(outdir, outdir_length, L"%s", fname);
}
開發者ID:KMayne,項目名稱:5minutebreak,代碼行數:17,代碼來源:ExecutablePath.cpp

示例10: test_policy_priv_by_id

static int test_policy_priv_by_id(const char *bus,
				  struct kdbus_conn *conn_dst,
				  bool drop_second_user,
				  int parent_status,
				  int child_status)
{
	int ret = 0;
	uint64_t expected_cookie = time(NULL) ^ 0xdeadbeef;

	ASSERT_RETURN(conn_dst);

	ret = RUN_UNPRIVILEGED_CONN(unpriv, bus, ({
		ret = kdbus_msg_send(unpriv, NULL,
				     expected_cookie, 0, 0, 0,
				     conn_dst->id);
		ASSERT_EXIT(ret == child_status);
	}));
開發者ID:D-os,項目名稱:kdbus,代碼行數:17,代碼來源:test-policy-priv.c

示例11: no_cancel_sync

static int no_cancel_sync(struct kdbus_conn *conn_src,
			  struct kdbus_conn *conn_dst)
{
	pid_t pid;
	int cancel_fd;
	int ret, status;
	struct kdbus_msg *msg = NULL;

	/* pass eventfd, but never signal it so it shouldn't have any effect */

	cancel_fd = eventfd(0, 0);
	ASSERT_RETURN_VAL(cancel_fd >= 0, cancel_fd);

	cookie++;
	pid = fork();
	ASSERT_RETURN_VAL(pid >= 0, pid);

	if (pid == 0) {
		ret = kdbus_msg_send_sync(conn_dst, NULL, cookie,
					  KDBUS_MSG_EXPECT_REPLY,
					  100000000ULL, 0, conn_src->id,
					  cancel_fd);
		ASSERT_EXIT(ret == 0);

		_exit(EXIT_SUCCESS);
	}

	ret = kdbus_msg_recv_poll(conn_src, 100, &msg, NULL);
	ASSERT_RETURN_VAL(ret == 0 && msg->cookie == cookie, -1);

	kdbus_msg_free(msg);

	ret = kdbus_msg_send_reply(conn_src, cookie, conn_dst->id);
	ASSERT_RETURN_VAL(ret >= 0, ret);

	ret = waitpid(pid, &status, 0);
	ASSERT_RETURN_VAL(ret >= 0, ret);

	if (WIFSIGNALED(status))
		return -1;

	return (status == EXIT_SUCCESS) ? 0 : -1;
}
開發者ID:adhideguchi,項目名稱:kdbus,代碼行數:43,代碼來源:test-sync.c


注:本文中的ASSERT_EXIT函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。