Example #1
0
void digidoc::DigestTest::testDigest(int method, const std::string& name, const std::string uri,
        int size, unsigned char* emptyDigest, unsigned char* expectedDigest)
{
    std::auto_ptr<Digest> calc = Digest::create(method);

    // Test digest getters.
    CPPUNIT_ASSERT_EQUAL(method, calc->getMethod());
    CPPUNIT_ASSERT_EQUAL(name, calc->getName());
    CPPUNIT_ASSERT_EQUAL(uri, calc->getUri());
    CPPUNIT_ASSERT_EQUAL(size, calc->getSize());

    // Test empty digest calculation by calling finalize without update.
    std::string msg = util::String::format("Empty %s digest does not match.", name.c_str());
    CPPUNIT_ASSERT_MESSAGE(msg, memcmp(emptyDigest, &calc->getDigest()[0], size) == 0);

    // Test empty digest calculation, calculate from buffer with size 0;
    calc = Digest::create(method);
    calc->update(emptyDigest, 0);
    CPPUNIT_ASSERT_MESSAGE(msg, memcmp(emptyDigest, &calc->getDigest()[0], size) == 0);

    // Test that digest update fails after finalize is called.
    msg = util::String::format("%s digest update did not throw an exception after finalize.", name.c_str());
    CPPUNIT_ASSERT_THROW_MESSAGE(msg, calc->update(emptyDigest, size), IOException);

    // Test that calculating digest from NULL pointer buffer fails.
    calc = Digest::create(method);
    msg = util::String::format("%s digest calculation from NULL pointer buffer did not throw an exception.", name.c_str());
    CPPUNIT_ASSERT_THROW_MESSAGE(msg, calc->update(NULL, size), IOException);

    // Test digest calculation, calculate digest from empty digest value.
    calc = Digest::create(method);
    calc->update(emptyDigest, size);
    msg = util::String::format("%s digest does not match.", name.c_str());
    CPPUNIT_ASSERT_MESSAGE(msg, memcmp(expectedDigest, &calc->getDigest()[0], size) == 0);
}
    void TestUnsupportedValues()
    {
        SCX_RunAsAdminProvider conf = GivenAdminProviderWithEmptyConfiguration();

        CPPUNIT_ASSERT_THROW_MESSAGE( "exception is expected for unsupported property",
            conf.Set(L"AllowRoot", L"blaha"),
            SCXAdminException );
        
        CPPUNIT_ASSERT_THROW_MESSAGE( "exception is expected for unsupported property",
            conf.Set(L"NotSupported", L"/what/ever/"),
            SCXAdminException );
    }
    // Negative test to set invalid entry: should throw an exception
    void testSetInvalidSeverityThrows()
    {
        SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf"));
        SCX_LogConfigurator invTest(cfgfile);

        invTest.Set( L"STDOUT", L"trace" );

        CPPUNIT_ASSERT_THROW_MESSAGE( "invalid severity string: anything1",
            invTest.Set( L"STDOUT:scxtest.core.common.pal.system.common.entityenumeration", L"anything" ),
            SCXAdminException );

        CPPUNIT_ASSERT_THROW_MESSAGE( "invalid severity string: anything2",
            invTest.Set( L"FILE:/myvar/opt/microsoft/scx/log/scx.log:scxtest.core.common.pal.system.common.entityenumeration", L"anything2" ),
            SCXAdminException );
    }
    // provider set
    void testProvRemoveLogfile()
    {
        // create a file
        SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf"));

        {
            SCX_LogConfigurator subject(cfgfile);

            subject.Set( L"STDOUT", L"trace" );
            subject.Set( L"STDOUT:scxtest.core.common.pal.system.common.entityenumeration", L"info" );
            subject.Set( L"FILE:/myvar/opt/microsoft/scx/log/scx.log:scxtest.core.common.pal.system.common.entityenumeration", L"info" );
        }
        
        SCX_LogConfigurator subject(cfgfile);

        subject.Remove( L"STDOUT" );

        CPPUNIT_ASSERT_THROW_MESSAGE( "exception is expected since entry does not exist",
            subject.Remove( L"FILE:/var/opt/microsoft/scx/log/scx.log" ),
            SCXAdminException );

        std::string str = GetFileContent(cfgfile);

        // we should not see these entries
        CPPUNIT_ASSERT( str.find("HYSTERICAL")  == str.npos );
        CPPUNIT_ASSERT( str.find("/var")  == str.npos );
        CPPUNIT_ASSERT( str.find("STDOUT")  == str.npos );

        // but should see these:
        CPPUNIT_ASSERT( str.find("FILE")  != str.npos );
        CPPUNIT_ASSERT( str.find("PATH: /myvar/opt/microsoft/scx/log/scx.log")  != str.npos );
        CPPUNIT_ASSERT( str.find("MODULE: scxtest.core.common.pal.system.common.entityenumeration INFO")  != str.npos );
    }
Example #5
0
void
ProcessTest::testWaitExitWithSignal()
{
	CPPUNIT_ASSERT_THROW_MESSAGE("spawned process exited abnormally but wait did not throw",
			ProcessControl::Process("./spawned_process").wait(),
			std::runtime_error);
}
Example #6
0
void
ProcessTest::testConstructorExecFailure()
{
	CPPUNIT_ASSERT_THROW_MESSAGE("constructor did not throw exception",
			ProcessControl::Process("sfasdf 242"),
			std::exception);
}
  void ImageCastFloatToFloatTensor_EmptyImage_ThrowsException()
  {
    mitk::Image::Pointer m_TestImage = GetEmptyTestImageWithGeometry(mitk::MakeScalarPixelType<float>());
    itk::Image<itk::DiffusionTensor3D<float>, 3>::Pointer diffImage;

    CPPUNIT_ASSERT_THROW_MESSAGE("Casting scalar float (MITK) image to scalar float (ITK) throws exception.",
                                 mitk::CastToItkImage(m_TestImage, diffImage),
                                 mitk::AccessByItkException);
  }
  void TestSerializerForExceptions()
  {
    mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New();

    //create an invalid filename
    std::string filename = std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"";

    //now try to serialize an check if an exception is thrown
    CPPUNIT_ASSERT_THROW_MESSAGE("Test serialization with empty storage and invalid filename, an exception is expected.",m_Serializer->Serialize(filename,myStorage),mitk::IGTException);
  }
Example #9
0
    void TestSetStackSizeError()
    {
        const size_t c_goodstacksize = 256000;
        const size_t c_badstacksize = 1;

        SCXCoreLib::SCXThreadAttr threadAttr;
        CPPUNIT_ASSERT_NO_THROW(threadAttr.SetStackSize(c_goodstacksize));
        
        SCXCoreLib::SCXThreadAttr threadAttrError;
        CPPUNIT_ASSERT_THROW_MESSAGE("SCXInternalErrorException exception expected", threadAttrError.SetStackSize(c_badstacksize), SCXCoreLib::SCXInternalErrorException);
        SCXUNIT_ASSERTIONS_FAILED(1);
    }
  void TestFilterWithInvalidPath()
  {
  #ifdef WIN32
  std::string filename = "XV:/342INVALID<>"; //invalid filename for windows
  #else
  std::string filename = "/dsfdsf:$�$342INVALID"; //invalid filename for linux
  #endif

  m_TestFilter->SetInput(m_RealTestImage);
  m_TestFilter->Update();
  CPPUNIT_ASSERT_THROW_MESSAGE("Testing if correct exception if thrown if an invalid path is given.",
                               m_TestFilter->SaveImages(filename),
                               mitk::Exception);
  }
  void TestWriteStorageToInvalidFile()
  {
    //create Tool Storage
    mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorageTestHelper::CreateTestData_SimpleStorage();

    //create invalid filename
  #ifdef WIN32
    std::string filename = "C:\342INVALIDFILE<>.storage"; //invalid filename for windows
  #else
    std::string filename = "/dsfdsf:$�$342INVALIDFILE.storage"; //invalid filename for linux
  #endif

    //test serialization (should throw exception)
    CPPUNIT_ASSERT_THROW_MESSAGE("Test serialization with simple storage and invalid filename, an exception is expected.",m_Serializer->Serialize(filename,myStorage),mitk::IGTException);
  }
Example #12
0
    void TestMarshalException(void)
    {
        // Marshal an integer
        stringstream stream;
        SCXCoreLib::Marshal msobj(stream);
        int val = 10;
        msobj.Write(val);

        // UnMarshal as a string - should raise exception
        SCXCoreLib::UnMarshal unobj(stream);
        std::wstring ws;

        CPPUNIT_ASSERT_THROW_MESSAGE(
            "\"SCXMarshalFormatException\" exception expected",
            unobj.Read(ws),
            SCXCoreLib::SCXMarshalFormatException);
    }
  void ImageCastToItkAndBack_SamePointer_Success()
  {
    typedef itk::Image<short, 3> ItkImageType;
    ItkImageType::Pointer itkImage = ItkImageType::New();

    std::string m_ImagePath = GetTestDataFilePath("Pic3D.nrrd");
    mitk::Image::Pointer testDataImage = mitk::IOUtil::LoadImage(m_ImagePath);

    // modify ITK image
    itk::Matrix<double, 3, 3> dir = itkImage->GetDirection();
    dir *= 2;
    itkImage->SetDirection(dir);

    CPPUNIT_ASSERT_THROW_MESSAGE("No exception thrown for casting back the same memory",
                                 testDataImage = mitk::GrabItkImageMemory(itkImage, testDataImage),
                                 itk::ExceptionObject);
    CPPUNIT_ASSERT(testDataImage.IsNotNull());
  }
    void TestReset()
    {
        SCX_RunAsAdminProvider conf = GivenAdminProviderWithEmptyConfiguration();

        CPPUNIT_ASSERT(conf.Set(L"ChRootPath", L"/what/ever/"));
        CPPUNIT_ASSERT(conf.Set(L"CWD", L"/foo/bar/"));
        CPPUNIT_ASSERT(conf.Set(L"AllowRoot", L"false"));

        CPPUNIT_ASSERT(conf.Reset(L"ChRootPath"));
        CPPUNIT_ASSERT(conf.Reset(L"CWD"));
        CPPUNIT_ASSERT(conf.Reset(L"AllowRoot"));

        CPPUNIT_ASSERT_THROW_MESSAGE( "exception is expected for unsupported property",
            conf.Reset(L"NotSupported"),
            SCXAdminException );
        
        std::wostringstream buf;
        CPPUNIT_ASSERT(conf.Print(buf));
        CPPUNIT_ASSERT(L"CWD = /var/opt/microsoft/scx/tmp/\nChRootPath = \nAllowRoot = true\n" == buf.str());
    }
Example #15
0
void TestUtils::format()
{
	CPPUNIT_ASSERT_EQUAL(std::string("texttext"), Utils::format("texttext", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL(std::string("a1,2"), Utils::format("a{0},{1}", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL(std::string(""), Utils::format("{2}", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No arguments", std::string("{0}"), Utils::format("{0}"));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No arguments", std::string("{-1}"), Utils::format("{-1}"));
	CPPUNIT_ASSERT_THROW_MESSAGE("Not enough arguments", Utils::format("{1}", 0), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Negative argument", Utils::format("{-1}", 0), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unclosed brace 1", Utils::format("{0", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unclosed brace 2", Utils::format("{0}}", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unopened brace 1", Utils::format("0}", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unopened brace 2", Utils::format("{{0}", 0, 1), std::invalid_argument);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 1", std::string("{0}"), Utils::format("{{0}}", 0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 2", std::string("{0"), Utils::format("{{0", 0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 3", std::string("0}"), Utils::format("0}}", 0));
}