Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sal/types.h>
30 : : #include <cppunit/TestFixture.h>
31 : : #include <cppunit/extensions/HelperMacros.h>
32 : : #include <cppunit/plugin/TestPlugIn.h>
33 : : #include <osl/file.hxx>
34 : : #include <osl/thread.h>
35 : : #include <rtl/ustring.hxx>
36 : :
37 : : using namespace osl;
38 : :
39 : : using ::rtl::OUString;
40 : : using ::rtl::OUStringToOString;
41 : : using ::rtl::OString;
42 : :
43 [ - + ]: 15 : class test_osl_writeFile : public CppUnit::TestFixture
44 : : {
45 : : public:
46 : 5 : void wrt_file()
47 : : {
48 : : FileBase::RC err;
49 : :
50 : : //create a tempfile
51 : 5 : rtl::OUString aTmpFile;
52 [ + - ]: 5 : err = FileBase::createTempFile(NULL, NULL, &aTmpFile);
53 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("temp File creation failed", err == osl::FileBase::E_None);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
54 : :
55 : : //now attempt to open with Create flag an existing file, should get E_EXIST
56 : 5 : File tmp_file(aTmpFile);
57 [ + - ]: 5 : err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create);
58 : :
59 : 5 : rtl::OString sErrorMsg = "Expected that '";
60 [ + - ]: 5 : sErrorMsg += rtl::OUStringToOString(aTmpFile, RTL_TEXTENCODING_ASCII_US);
61 : 5 : sErrorMsg += "' would exist!";
62 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE(sErrorMsg.getStr(), err == FileBase::E_EXIST);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
63 : :
64 : : char buffer[1];
65 : 5 : sal_uInt64 written = 0;
66 [ + - ]: 5 : err = tmp_file.write((void*)buffer, sizeof(buffer), written);
67 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("write on unconnected file should fail",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
68 [ + - ]: 5 : err != osl::FileBase::E_None && written == 0);
69 : :
70 [ + - ]: 5 : err = tmp_file.sync();
71 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("sync on unconnected file should fail", err != FileBase::E_None);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
72 [ + - ]: 5 : err = tmp_file.close();
73 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("close on unconnected file should fail", err != FileBase::E_None);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
74 : :
75 [ + - ]: 5 : err = ::osl::File::remove(aTmpFile);
76 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_MESSAGE("temp file should have existed", err == FileBase::E_None);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
77 : 5 : }
78 : :
79 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(test_osl_writeFile);
[ + - ][ + - ]
[ # # ]
80 [ + - ][ + - ]: 5 : CPPUNIT_TEST(wrt_file);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
81 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
82 : : };
83 : :
84 : : //#####################################
85 : : // register test suites
86 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(test_osl_writeFile);
87 : :
88 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
89 : :
90 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|