1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
24 #include <osl/file.hxx>
25 #include <osl/thread.h>
26 #include <rtl/ustring.hxx>
30 using ::rtl::OUString
;
31 using ::rtl::OUStringToOString
;
34 class test_osl_writeFile
: public CppUnit::TestFixture
42 rtl::OUString aTmpFile
;
43 err
= FileBase::createTempFile(NULL
, NULL
, &aTmpFile
);
44 CPPUNIT_ASSERT_MESSAGE("temp File creation failed", err
== osl::FileBase::E_None
);
46 //now attempt to open with Create flag an existing file, should get E_EXIST
47 File
tmp_file(aTmpFile
);
48 err
= tmp_file
.open(osl_File_OpenFlag_Write
| osl_File_OpenFlag_Create
);
50 rtl::OString sErrorMsg
= "Expected that '";
51 sErrorMsg
+= rtl::OUStringToOString(aTmpFile
, RTL_TEXTENCODING_ASCII_US
);
52 sErrorMsg
+= "' would exist!";
53 CPPUNIT_ASSERT_MESSAGE(sErrorMsg
.getStr(), err
== FileBase::E_EXIST
);
56 sal_uInt64 written
= 0;
57 err
= tmp_file
.write((void*)buffer
, sizeof(buffer
), written
);
58 CPPUNIT_ASSERT_MESSAGE("write on unconnected file should fail",
59 err
!= osl::FileBase::E_None
&& written
== 0);
61 err
= tmp_file
.sync();
62 CPPUNIT_ASSERT_MESSAGE("sync on unconnected file should fail", err
!= FileBase::E_None
);
63 err
= tmp_file
.close();
64 CPPUNIT_ASSERT_MESSAGE("close on unconnected file should fail", err
!= FileBase::E_None
);
66 err
= ::osl::File::remove(aTmpFile
);
67 CPPUNIT_ASSERT_MESSAGE("temp file should have existed", err
== FileBase::E_None
);
70 CPPUNIT_TEST_SUITE(test_osl_writeFile
);
71 CPPUNIT_TEST(wrt_file
);
72 CPPUNIT_TEST_SUITE_END();
75 // register test suites
76 CPPUNIT_TEST_SUITE_REGISTRATION(test_osl_writeFile
);
78 CPPUNIT_PLUGIN_IMPLEMENT();
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */