TEST(SandboxBrokerPolicyLookup, CopyCtor)
{
  SandboxBroker::Policy psrc;
  psrc.AddPath(MAY_READ | MAY_WRITE, "/dev/null", AddAlways);
  SandboxBroker::Policy pdst(psrc);
  psrc.AddPath(MAY_READ, "/dev/zero", AddAlways);
  pdst.AddPath(MAY_READ, "/dev/urandom", AddAlways);

  EXPECT_EQ(MAY_ACCESS | MAY_READ | MAY_WRITE, psrc.Lookup("/dev/null"))
    << "Common path absent in copy source.";
  EXPECT_EQ(MAY_ACCESS | MAY_READ | MAY_WRITE, pdst.Lookup("/dev/null"))
    << "Common path absent in copy destination.";

  EXPECT_EQ(MAY_ACCESS | MAY_READ, psrc.Lookup("/dev/zero"))
    << "Source-only path is absent.";
  EXPECT_EQ(0, pdst.Lookup("/dev/zero"))
    << "Source-only path is present in copy destination.";

  EXPECT_EQ(0, psrc.Lookup("/dev/urandom"))
    << "Destination-only path is present in copy source.";
  EXPECT_EQ(MAY_ACCESS | MAY_READ, pdst.Lookup("/dev/urandom"))
    << "Destination-only path is absent.";

  EXPECT_EQ(0, psrc.Lookup("/etc/passwd"))
    << "Non-added path is present in copy source.";
  EXPECT_EQ(0, pdst.Lookup("/etc/passwd"))
    << "Non-added path is present in copy source.";
}
Example #2
0
			static detail::auto_ptr<T> auto_ptr_dynamic_cast(detail::auto_ptr<TS> psrc)
			{
				TS* sptr = psrc.raw_ptr();
				T* dptr = (T*)sptr;
				auto_ptr<T> pdst(dptr);
				pdst->retain();
				return pdst;
			}
Example #3
0
/** @functions */
void FaceAligner::align_faces(IplImage *fimg, CvRect& face, const CvRect& refface) {
	int i, j;
	CVec2d srcpts[4];
	CVec2d dstpts[4];

	srcpts[0].x = face.x;
	srcpts[0].y = face.y;
	dstpts[0].x = refface.x;
	dstpts[0].y = refface.y;

	srcpts[1].x = face.x + face.width;
	srcpts[1].y = face.y;
	dstpts[1].x = refface.x + refface.width;
	dstpts[1].y = refface.y;

	srcpts[2].x = face.x + face.width;
	srcpts[2].y = face.y + face.height;
	dstpts[2].x = refface.x + refface.width;
	dstpts[2].y = refface.y + refface.height;

	srcpts[3].x = face.x;
	srcpts[3].y = face.y + face.height;
	dstpts[3].x = refface.x;
	dstpts[3].y = refface.y + refface.height;

	double** Hmat = new double*[3];
	double** Hinv = new double*[3];
	for(i=0; i<3; i++) {
		Hmat[i] = new double[3];
		Hinv[i] = new double[3];
	}

	CHomography homography;
	homography.compute(srcpts, dstpts, 4);

	for(j=0; j<3; j++) {
		for(i=0; i<3; i++) {
			Hmat[j][i] = homography.m_dData[j][i];
		}
	}
	homography.computeInverse(Hmat, Hinv);

	ARgbImage pfimg(fimg);
	IplImage *fcpy = cvCreateImage( cvSize(fimg->width,fimg->height), IPL_DEPTH_64F, 3 );
	RgbImageDbl pfcpy(fcpy);
	for(j=0; j<fimg->height; j++) {
		for(i=0; i<fimg->width; i++) {
			pfcpy[j][i].r = (double)pfimg[j][i].r;
			pfcpy[j][i].g = (double)pfimg[j][i].g;
			pfcpy[j][i].b = (double)pfimg[j][i].b;
		}
	}

	IplImage *dst = cvCreateImage( cvSize(fimg->width,fimg->height), IPL_DEPTH_64F, 3 );
	RgbImageDbl pdst(dst);

	warp_img(fcpy, dst, Hinv);
//	CvMat matA = cvMat(3,3,CV_64FC1,homography.m_dData);
//	CWarping::PerspectiveTransform2(fcpy, dst, &matA);
//	cvPerspectiveTransform(fcpy,dst,&matA);

	for(j=0; j<fimg->height; j++) {
		for(i=0; i<fimg->width; i++) {
			pfimg[j][i].r = (BYTE)pdst[j][i].r;
			pfimg[j][i].g = (BYTE)pdst[j][i].g;
			pfimg[j][i].b = (BYTE)pdst[j][i].b;
			pfimg[j][i].a = 255;
		}
	}

	for(i=0; i<3; i++)
	{
		delete [] Hmat[i];
		delete [] Hinv[i];
	}
	delete [] Hmat;
	delete [] Hinv;

	cvReleaseImage(&fcpy);
	cvReleaseImage(&dst);
}
Example #4
0
	int detectInputCodepage(int autodetectType, int defcodepage, const char *data, size_t size)
	{
		int codepage;
		IMLangConvertCharset *pcc;
		UINT dstsize;
		UINT srcsize;
		HRESULT hr;

		hr = m_pmlang->CreateConvertCharset(autodetectType, ucr::CP_UCS2LE, MLCONVCHARF_AUTODETECT, &pcc);
		if (FAILED(hr))
			return defcodepage;
		srcsize = static_cast<UINT>(size);
		dstsize = static_cast<UINT>(size * sizeof(wchar_t));
		std::unique_ptr<unsigned char[]> pdst(new unsigned char[size * sizeof(wchar_t)]);
		SetLastError(0);
		hr = pcc->DoConversion((unsigned char *)data, &srcsize, pdst.get(), &dstsize);
		pcc->GetSourceCodePage((unsigned *)&codepage);
		if (FAILED(hr) || GetLastError() == ERROR_NO_UNICODE_TRANSLATION || codepage == autodetectType)
		{
			int codepagestotry[3] = {0};
			if (codepage == autodetectType)
			{
				if (size < 2 || (data[0] != 0 && data[1] != 0))
				{
					codepagestotry[0] = defcodepage;
					codepagestotry[1] = ucr::CP_UTF_8;
				}
			}
			else
			{
				if (size < 2 || (data[0] != 0 && data[1] != 0))
					codepagestotry[0] = ucr::CP_UTF_8;
			}
			codepage = defcodepage;
			size_t i;
			for (i = 0; i < sizeof(codepagestotry)/sizeof(codepagestotry[0]) - 1; i++)
			{
				if (codepagestotry[i] == 0) break;
				pcc->Initialize(codepagestotry[i], ucr::CP_UCS2LE, 0);
				srcsize = static_cast<UINT>(size);
				dstsize = static_cast<UINT>(size * sizeof(wchar_t));
				SetLastError(0);
				hr = pcc->DoConversion((unsigned char *)data, &srcsize, pdst.get(), &dstsize);
				if (FAILED(hr) || GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
					continue;
				codepage = codepagestotry[i];
				break;
			}
			if (codepagestotry[i] == 0 && (size % 2) == 0)
			{
				// UCS-2
				int lezerocount = 0;
				int lecrorlf = 0;
				int bezerocount = 0;
				int becrorlf = 0;
				for (i = 0; i < size; i += 2)
				{
					if (data[i] == 0)
					{
						bezerocount++;
						if (data[i + 1] == 0x0a || data[i + 1] == 0x0d)
							becrorlf++;
					}
					else if (data[i + 1] == 0)
					{
						lezerocount++;
						if (data[i] == 0x0a || data[i] == 0x0d)
							lecrorlf++;
					}
				}
				if (lezerocount > 0 || bezerocount > 0)
				{
					if ((lecrorlf == 0 && size < 512 || (lecrorlf > 0 && (size / lecrorlf > 1024))) && lezerocount > bezerocount)
						codepage = ucr::CP_UCS2LE;
					else if ((becrorlf == 0 && size < 512 || (becrorlf > 0 && (size / becrorlf > 1024))) && lezerocount < bezerocount)
						codepage = ucr::CP_UCS2BE;
				}
			}
		}
		if (codepage == 20127)
			return defcodepage;
		return codepage;
	}