Esempio n. 1
0
static void expect(int fd, const char *pattern)
{
    char buffer[PIPE_BUF+1];
    int r;

    r = read(fd, buffer, sizeof(buffer)-1);
    if (r < 0)
        failmsg("reading from pipe");
    buffer[r] = '\0';

    if (fnmatch(pattern, buffer, 0) != 0)
        failmsg("Expected '%s' got '%s'", pattern, buffer);
}
Esempio n. 2
0
IWorkbenchWindow::Pointer UITestCase::OpenTestWindow(
    const std::string& perspectiveId)
{
  try
  {
    IWorkbenchWindow::Pointer window = fWorkbench->OpenWorkbenchWindow(
        perspectiveId, GetPageInput());
    WaitOnShell(window->GetShell());
    return window;
  } catch (WorkbenchException& e)
  {
    failmsg(e.displayText());
    return IWorkbenchWindow::Pointer(0);
  }
}
Esempio n. 3
0
static void check_opt(const struct opt_table *entry)
{
	const char *p;
	unsigned len;

	if (entry->type != OPT_HASARG && entry->type != OPT_NOARG
	    && entry->type != (OPT_EARLY|OPT_HASARG)
	    && entry->type != (OPT_EARLY|OPT_NOARG))
		failmsg("Option %s: unknown entry type %u",
			entry->names, entry->type);

	if (!entry->desc)
		failmsg("Option %s: description cannot be NULL", entry->names);


	if (entry->names[0] != '-')
		failmsg("Option %s: does not begin with '-'", entry->names);

	for (p = first_name(entry->names, &len); p; p = next_name(p, &len)) {
		if (*p == '-') {
			if (len == 1)
				failmsg("Option %s: invalid long option '--'",
					entry->names);
			opt_num_long++;
		} else {
			if (len != 1)
				failmsg("Option %s: invalid short option"
					" '%.*s'", entry->names, len+1, p-1);
			opt_num_short++;
			if (entry->type == OPT_HASARG)
				opt_num_short_arg++;
		}
		/* Don't document args unless there are some. */
		if (entry->type == OPT_NOARG) {
			if (p[len] == ' ' || p[len] == '=')
				failmsg("Option %s: does not take arguments"
					" '%s'", entry->names, p+len+1);
		}
	}
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int        p[2];
    int        stdoutfd;
        struct obj exp;

        (void)argc;
        (void)argv;

    printf("1..1\n");
    fflush(stdout);
    stderrfd = dup(STDERR_FILENO);

    if (stderrfd < 0)
        err(1, "dup of stderr failed");

    stdoutfd = dup(STDOUT_FILENO);

    if (stdoutfd < 0)
        err(1, "dup of stdout failed");

    if (pipe(p) != 0)
        failmsg("pipe failed");

    if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
        failmsg("Duplicating file descriptor");

    plan_tests(10);
    expect(p[0], "1..10\n");

    ok(1, "msg1");
    expect(p[0], "ok 1 - msg1\n");

    ok(0, "msg2");
    expect(p[0], "not ok 2 - msg2\n"
           "#     Failed test (*test.1.tap.c:main() at line 199)\n");

    ok1(true);
    expect(p[0], "ok 3 - true\n");

    ok1(false);
    expect(p[0], "not ok 4 - false\n"
           "#     Failed test (*test.1.tap.c:main() at line 206)\n");

    pass("passed");
    expect(p[0], "ok 5 - passed\n");

    fail("failed");
    expect(p[0], "not ok 6 - failed\n"
           "#     Failed test (*test.1.tap.c:main() at line 213)\n");

    skip(2, "skipping %s", "test");
    expect(p[0], "ok 7 # skip skipping test\n"
           "ok 8 # skip skipping test\n");

    todo_start("todo");
    ok1(false);
    expect(p[0], "not ok 9 - false # TODO todo\n"
                 "#     Failed (TODO) test (*test.1.tap.c:main() at line 222)\n");
    ok1(true);
    expect(p[0], "ok 10 - true # TODO todo\n");
    todo_end();

    if (exit_status() != 3)
        failmsg("Expected exit status 3, not %i", exit_status());

        is(one_int(), 1, "one_int() returns 1");
        expect(p[0], "ok 11 - one_int() returns 1\n");
        is(one_int(), 2, "one_int() returns 2");
        expect(p[0], "not ok 12 - one_int() returns 2\n"
               "#     Failed test (*test.1.tap.c:main() at line 234)\n"
               "#          got: 1\n"
               "#     expected: 2\n");

        is_eq(one_str(), "one", "one_str() returns 'one'");
        expect(p[0], "ok 13 - one_str() returns 'one'\n");
        is_eq(one_str(), "two", "one_str() returns 'two'");
        expect(p[0], "not ok 14 - one_str() returns 'two'\n"
               "#     Failed test (*test.1.tap.c:main() at line 242)\n"
               "#          got: \"one\"\n"
               "#     expected: \"two\"\n");

        exp.id = 1;
        is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 1");
        expect(p[0], "ok 15 - one_obj() has id 1\n");
        exp.id = 2;
        is_cmp(one_obj(), &exp, obj_cmp, obj_to_str, "one_obj() has id 2");
        expect(p[0], "not ok 16 - one_obj() has id 2\n"
               "#     Failed test (*test.1.tap.c:main() at line 252)\n"
               "#          got: {id=1}\n"
               "#     expected: {id=2}\n");

        is_strstr(one_str(), "n", "one_str() contains 'n'");
        expect(p[0], "ok 17 - one_str() contains 'n'\n");
        is_strstr(one_str(), "w", "one_str() contains 'w'");
        expect(p[0], "not ok 18 - one_str() contains 'w'\n"
               "#     Failed test (*test.1.tap.c:main() at line 260)\n"
               "#                     got: \"one\"\n"
               "#     expected to contain: \"w\"\n");
#if 0
    /* Manually run the atexit command. */
    _cleanup();
    expect(p[0], "# Looks like you failed 2 tests of 9.\n");
#endif

    write_all(stdoutfd, "ok 1 - All passed\n",
          strlen("ok 1 - All passed\n"));
    _exit(0);
}
Esempio n. 5
0
  void PreferencesTest::TestAll()
  {
    IPreferencesService::Pointer prefService = Platform::GetServiceRegistry().GetServiceById<IPreferencesService>(IPreferencesService::ID);
    assert(prefService.IsNotNull());

    /// Test for: IPreferences::GetSystemPreferences()
    IPreferences::Pointer root = prefService->GetSystemPreferences();
    assert(root.IsNotNull());

    {
      BERRY_INFO << "testing Preferences::Node(), Preferences::NodeExists(), Preferences::Parent(), "
        "Preferences::ChildrenNames(), Preferences::RemoveNode()";

      berry::IPreferences::Pointer editorsNode(0);
      editorsNode = root->Node("/editors");
      assert(editorsNode.IsNotNull());

      assert(editorsNode->NodeExists("/editors"));

      assert(editorsNode->Parent() == root);

      berry::IPreferences::Pointer editorsGeneralNode = root->Node("/editors/general");
      assert(editorsNode->NodeExists("/editors/general"));

      berry::IPreferences::Pointer editorsSyntaxNode = root->Node("/editors/syntax");
      assert(editorsGeneralNode->NodeExists("/editors/syntax"));

      berry::IPreferences::Pointer editorsFontNode = root->Node("/editors/font");
      assert(editorsSyntaxNode->NodeExists("/editors/font"));

      vector<string> childrenNames;
      childrenNames.push_back("general");
      childrenNames.push_back("syntax");
      childrenNames.push_back("font");
      assert(editorsNode->ChildrenNames() == childrenNames);

      editorsFontNode->RemoveNode();
      try {
        editorsFontNode->Parent();
        failmsg("this should throw a Poco::IllegalStateException");
      }
      catch (Poco::IllegalStateException)
      {
        // expected
      }
    }

    // testing methods
    // Preferences::put*()
    // Preferences::get*()
    {
      BERRY_INFO << "testing Preferences::put*(), Preferences::get*(), OnChanged";

      assert(root->NodeExists("/editors/general"));
      berry::IPreferences::Pointer editorsGeneralNode = root->Node("/editors/general");

      IBerryPreferences::Pointer berryEditorsGeneralNode = editorsGeneralNode.Cast< IBerryPreferences >();
      assert(berryEditorsGeneralNode.IsNotNull());

      TestPreferencesChangedListener listener(berryEditorsGeneralNode.GetPointer());

      std::string strKey = "Bad words";std::string strValue = "badword1 badword2";
      editorsGeneralNode->Put(strKey, strValue);

      assert(listener.numCalled == 1);
      assert(editorsGeneralNode->Get(strKey, "") == strValue);
      assert(editorsGeneralNode->Get("wrong key", "default value") == "default value");

      strKey = "Show Line Numbers";bool bValue = true;
      editorsGeneralNode->PutBool(strKey, bValue);
      assert(listener.numCalled == 2);
      assert(editorsGeneralNode->GetBool(strKey, !bValue) == bValue);

      strKey = "backgroundcolor"; strValue = "#00FF00";
      editorsGeneralNode->PutByteArray(strKey, strValue);
      assert(listener.numCalled == 3);
      assert(editorsGeneralNode->GetByteArray(strKey, "") == strValue);

      strKey = "update time"; double dValue = 1.23;
      editorsGeneralNode->PutDouble(strKey, dValue);
      assert(editorsGeneralNode->GetDouble(strKey, 0.0) == dValue);

      strKey = "update time float"; float fValue = 1.23f;
      editorsGeneralNode->PutFloat(strKey, fValue);
      assert(editorsGeneralNode->GetFloat(strKey, 0.0f) == fValue);

      strKey = "Break on column"; int iValue = 80;
      editorsGeneralNode->PutInt(strKey, iValue);
      assert(editorsGeneralNode->GetInt(strKey, 0) == iValue);

      strKey = "Maximum number of words"; long lValue = 11000000;
      editorsGeneralNode->PutLong(strKey, lValue);
      assert(editorsGeneralNode->GetLong(strKey, 0) == lValue);
    }

  }
Esempio n. 6
0
Mat fromNDArrayToMat(PyObject* o) {
	cv::Mat m;
	bool allowND = true;
	if (!PyArray_Check(o)) {
		failmsg("argument is not a numpy array");
		if (!m.data)
			m.allocator = &g_numpyAllocator;
	} else {
		PyArrayObject* oarr = (PyArrayObject*) o;

		bool needcopy = false, needcast = false;
		int typenum = PyArray_TYPE(oarr), new_typenum = typenum;
		int type = typenum == NPY_UBYTE ? CV_8U : typenum == NPY_BYTE ? CV_8S :
					typenum == NPY_USHORT ? CV_16U :
					typenum == NPY_SHORT ? CV_16S :
					typenum == NPY_INT ? CV_32S :
					typenum == NPY_INT32 ? CV_32S :
					typenum == NPY_FLOAT ? CV_32F :
					typenum == NPY_DOUBLE ? CV_64F : -1;

		if (type < 0) {
			if (typenum == NPY_INT64 || typenum == NPY_UINT64
					|| type == NPY_LONG) {
				needcopy = needcast = true;
				new_typenum = NPY_INT;
				type = CV_32S;
			} else {
				failmsg("Argument data type is not supported");
				m.allocator = &g_numpyAllocator;
				return m;
			}
		}

#ifndef CV_MAX_DIM
		const int CV_MAX_DIM = 32;
#endif

		int ndims = PyArray_NDIM(oarr);
		if (ndims >= CV_MAX_DIM) {
			failmsg("Dimensionality of argument is too high");
			if (!m.data)
				m.allocator = &g_numpyAllocator;
			return m;
		}

		int size[CV_MAX_DIM + 1];
		size_t step[CV_MAX_DIM + 1];
		size_t elemsize = CV_ELEM_SIZE1(type);
		const npy_intp* _sizes = PyArray_DIMS(oarr);
		const npy_intp* _strides = PyArray_STRIDES(oarr);
		bool ismultichannel = ndims == 3 && _sizes[2] <= CV_CN_MAX;

		for (int i = ndims - 1; i >= 0 && !needcopy; i--) {
			// these checks handle cases of
			//  a) multi-dimensional (ndims > 2) arrays, as well as simpler 1- and 2-dimensional cases
			//  b) transposed arrays, where _strides[] elements go in non-descending order
			//  c) flipped arrays, where some of _strides[] elements are negative
			if ((i == ndims - 1 && (size_t) _strides[i] != elemsize)
					|| (i < ndims - 1 && _strides[i] < _strides[i + 1]))
				needcopy = true;
		}

		if (ismultichannel && _strides[1] != (npy_intp) elemsize * _sizes[2])
			needcopy = true;

		if (needcopy) {

			if (needcast) {
				o = PyArray_Cast(oarr, new_typenum);
				oarr = (PyArrayObject*) o;
			} else {
				oarr = PyArray_GETCONTIGUOUS(oarr);
				o = (PyObject*) oarr;
			}

			_strides = PyArray_STRIDES(oarr);
		}

		for (int i = 0; i < ndims; i++) {
			size[i] = (int) _sizes[i];
			step[i] = (size_t) _strides[i];
		}

		// handle degenerate case
		if (ndims == 0) {
			size[ndims] = 1;
			step[ndims] = elemsize;
			ndims++;
		}

		if (ismultichannel) {
			ndims--;
			type |= CV_MAKETYPE(0, size[2]);
		}

		if (ndims > 2 && !allowND) {
			failmsg("%s has more than 2 dimensions");
		} else {

			m = Mat(ndims, size, type, PyArray_DATA(oarr), step);
			m.u = g_numpyAllocator.allocate(o, ndims, size, type, step);
			m.addref();

			if (!needcopy) {
				Py_INCREF(o);
			}
		}
		m.allocator = &g_numpyAllocator;
	}
	return m;
}
bool numpy_to_mat(const PyObject* o, cv::Mat& m, const char* name, bool allowND)
{
  if(!o || o == Py_None)
    {
        if( !m.data )
            m.allocator = &g_numpyAllocator;
        return true;
    }

    if( !PyArray_Check(o) )
    {
        failmsg("%s is not a numpy array", name);
        return false;
    }

    int typenum = PyArray_TYPE(o);
    int type = typenum == NPY_UBYTE ? CV_8U : typenum == NPY_BYTE ? CV_8S :
               typenum == NPY_USHORT ? CV_16U : typenum == NPY_SHORT ? CV_16S :
               typenum == NPY_INT || typenum == NPY_LONG ? CV_32S :
               typenum == NPY_FLOAT ? CV_32F :
               typenum == NPY_DOUBLE ? CV_64F : -1;

    if( type < 0 )
    {
        failmsg("%s data type = %d is not supported", name, typenum);
        return false;
    }

    int ndims = PyArray_NDIM(o);
    if(ndims >= CV_MAX_DIM)
    {
        failmsg("%s dimensionality (=%d) is too high", name, ndims);
        return false;
    }

    int size[CV_MAX_DIM+1];
    size_t step[CV_MAX_DIM+1], elemsize = CV_ELEM_SIZE1(type);
    const npy_intp* _sizes = PyArray_DIMS(o);
    const npy_intp* _strides = PyArray_STRIDES(o);

    for(int i = 0; i < ndims; i++)
    {
        size[i] = (int)_sizes[i];
        step[i] = (size_t)_strides[i];
    }

    if( ndims == 0 || step[ndims-1] > elemsize ) {
        size[ndims] = 1;
        step[ndims] = elemsize;
        ndims++;
    }

    if( ndims == 3 && size[2] <= CV_CN_MAX && step[1] == elemsize*size[2] )
    {
        ndims--;
        type |= CV_MAKETYPE(0, size[2]);
    }

    if( ndims > 2 && !allowND )
    {
        failmsg("%s has more than 2 dimensions", name);
        return false;
    }

    m = Mat(ndims, size, type, PyArray_DATA(o), step);

    if( m.data )
    {
        m.refcount = refcountFromPyObject(o);
        m.addref(); // protect the original numpy array from deallocation
                    // (since Mat destructor will decrement the reference counter)
    };
    m.allocator = &g_numpyAllocator;
    return true;
}
Esempio n. 8
0
int main(int argc, char *argv[])
{
	int p[2];
	int stdoutfd;

	setbuf(stdout, 0);
	printf("1..1\n");
	stderrfd = dup(STDERR_FILENO);
	if (stderrfd < 0)
		err(1, "dup of stderr failed");

	stdoutfd = dup(STDOUT_FILENO);
	if (stdoutfd < 0)
		err(1, "dup of stdout failed");

	if (pipe(p) != 0)
		failmsg("pipe failed");

	if (dup2(p[1], STDERR_FILENO) < 0 || dup2(p[1], STDOUT_FILENO) < 0)
		failmsg("Duplicating file descriptor");

	plan_tests(10);
	expect(p[0], "1..10\n");

	ok(1, "msg1");
	expect(p[0], "ok 1 - msg1\n");

	ok(0, "msg2");
	expect(p[0], "not ok 2 - msg2\n"
	       "#     Failed test (*test/run.c:main() at line 91)\n");

	ok1(true);
	expect(p[0], "ok 3 - true\n");

	ok1(false);
 	expect(p[0], "not ok 4 - false\n"
	       "#     Failed test (*test/run.c:main() at line 98)\n");

	pass("passed");
 	expect(p[0], "ok 5 - passed\n");

	fail("failed");
 	expect(p[0], "not ok 6 - failed\n"
	       "#     Failed test (*test/run.c:main() at line 105)\n");

	skip(2, "skipping %s", "test");
 	expect(p[0], "ok 7 # skip skipping test\n"
	       "ok 8 # skip skipping test\n");

	todo_start("todo");
	ok1(false);
	expect(p[0], "not ok 9 - false # TODO todo\n"
	       "#     Failed (TODO) test (*test/run.c:main() at line 114)\n");
	ok1(true);
	expect(p[0], "ok 10 - true # TODO todo\n");
	todo_end();

	if (exit_status() != 3)
		failmsg("Expected exit status 3, not %i", exit_status());

#if 0
	/* Manually run the atexit command. */
	_cleanup();
	expect(p[0], "# Looks like you failed 2 tests of 9.\n");
#endif

	write_all(stdoutfd, "ok 1 - All passed\n",
		  strlen("ok 1 - All passed\n"));
	exit(0);
}
Esempio n. 9
0
void
_start(void)
{
	// WARNING: __hart_self_on_entry must be read before
	// anything is register-allocated!
	int id = __hart_self_on_entry;
	static int init = 0;
	// For dynamically-linked programs, the first time through,
	// __hart_self_on_entry could be clobbered (on x86), because
	// the linker will have overwritten eax.  Happily, the first
	// time through, we know we are vcore 0.  Subsequent entries
	// into this routine do not have this problem.
	if(init == 0)
		id = 0;
	
	// threads besides thread 0 must acquire a TCB.
	if(id != 0)
	{
		TLS_INIT_TP(__hart_thread_control_blocks[id],0);
		hart_entry();
		hart_yield();
		failmsg("why did hart_yield() return?");
		goto diediedie;
	}

	if(init)
	{
		failmsg("why did thread 0 re-enter _start?");
		goto diediedie;
	}
	init = 1;

	extern int main(int,char**,char**);
	extern void __libc_csu_init(int,char**,char**);
	extern void __libc_csu_fini(void);
	extern void __libc_start_main(typeof(&main),int,char**,
	              typeof(&__libc_csu_init),
	              typeof(&__libc_csu_fini),
	              void*,void*);

	char** argv = (char**)alloca(sizeof(__procinfo.argp));
	memcpy(argv,__procinfo.argp,sizeof(__procinfo.argp));

	char* argbuf = (char*)alloca(sizeof(__procinfo.argbuf));
	memcpy(argbuf,__procinfo.argbuf,sizeof(__procinfo.argbuf));

	for(int i = 0; i < PROCINFO_MAX_ARGP; i++)
		if(argv[i])
			argv[i] += argbuf - __procinfo.argbuf;

	int argc = 0;
	while(argv[argc])
		argc++;

	extern char** _environ;
	_environ = argv+argc+1;

	__libc_start_main(&main,argc,argv,&__libc_csu_init,&__libc_csu_fini,0,0);

	failmsg("why did main() return?");

diediedie:
	abort();
	#ifdef ABORT_INSTRUCTION
	ABORT_INSTRUCTION;
	#endif
	while(1);
}