You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
Added a more verbose error message to the constructor of the BufferedFile class.
This commit is contained in:
committed by
Leonid Fedorov
parent
817b092a2b
commit
ddfbeb192f
77
tests/BufferedFile.cpp
Normal file
77
tests/BufferedFile.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* Copyright (C) 2024 MariaDB Corporation.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; version 2 of
|
||||||
|
the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
MA 02110-1301, USA. */
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "BufferedFile.h"
|
||||||
|
|
||||||
|
std::string message(const std::string& fname, int err)
|
||||||
|
{
|
||||||
|
return std::string("unable to open file: ") + fname + ", exception: " + strerror(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BufferedFileTest, NoError)
|
||||||
|
{
|
||||||
|
const char fname[] = "/tmp/foo.bar";
|
||||||
|
std::ofstream out(fname);
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(idbdatafile::BufferedFile bf(fname, "r", 0));
|
||||||
|
remove(fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BufferedFileTest, NoEnt)
|
||||||
|
{
|
||||||
|
const char fname[] = "/home/BufferedFile_test";
|
||||||
|
|
||||||
|
EXPECT_THROW(
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
idbdatafile::BufferedFile bf(fname, "r", 0);
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& e)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(message(fname, ENOENT), e.what());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
std::runtime_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BufferedFileTest, NotDir)
|
||||||
|
{
|
||||||
|
std::string fake_dir_name = "/tmp/foo";
|
||||||
|
std::ofstream out(fake_dir_name);
|
||||||
|
std::string fname = fake_dir_name + "/bar";
|
||||||
|
|
||||||
|
EXPECT_THROW(
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
idbdatafile::BufferedFile bf(fname.c_str(), "r", 0);
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& e)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(message(fname, ENOTDIR), e.what());
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
std::runtime_error);
|
||||||
|
remove(fake_dir_name.c_str());
|
||||||
|
}
|
@ -101,6 +101,10 @@ if(WITH_UNITTESTS)
|
|||||||
columnstore_link(bytestream ${ENGINE_LDFLAGS} ${ENGINE_WRITE_LIBS} ${CPPUNIT_LIBRARIES} cppunit)
|
columnstore_link(bytestream ${ENGINE_LDFLAGS} ${ENGINE_WRITE_LIBS} ${CPPUNIT_LIBRARIES} cppunit)
|
||||||
add_test(NAME columnstore:bytestream COMMAND bytestream)
|
add_test(NAME columnstore:bytestream COMMAND bytestream)
|
||||||
|
|
||||||
|
add_executable(idbdatafile_test BufferedFile.cpp)
|
||||||
|
columnstore_link(idbdatafile_test ${ENGINE_LDFLAGS} ${ENGINE_WRITE_LIBS} gtest gtest_main)
|
||||||
|
add_test(NAME columnstore:idbdatafile_test COMMAND idbdatafile_test)
|
||||||
|
|
||||||
# standalone EM routines test
|
# standalone EM routines test
|
||||||
add_executable(brm_em_standalone brm-em-standalone.cpp)
|
add_executable(brm_em_standalone brm-em-standalone.cpp)
|
||||||
columnstore_link(brm_em_standalone ${ENGINE_LDFLAGS} ${ENGINE_WRITE_LIBS} ${CPPUNIT_LIBRARIES} cppunit)
|
columnstore_link(brm_em_standalone ${ENGINE_LDFLAGS} ${ENGINE_WRITE_LIBS} ${CPPUNIT_LIBRARIES} cppunit)
|
||||||
|
@ -31,10 +31,13 @@ BufferedFile::BufferedFile(const char* fname, const char* mode, unsigned opts)
|
|||||||
: IDBDataFile(fname), m_fp(0), m_buffer(0)
|
: IDBDataFile(fname), m_fp(0), m_buffer(0)
|
||||||
{
|
{
|
||||||
m_fp = fopen(fname, mode);
|
m_fp = fopen(fname, mode);
|
||||||
|
int err = errno;
|
||||||
|
|
||||||
if (m_fp == NULL)
|
if (m_fp == NULL)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("unable to open Buffered file ");
|
static string message = "unable to open file: ";
|
||||||
|
|
||||||
|
throw std::runtime_error(message + fname + ", exception: " + strerror(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
applyOptions(opts);
|
applyOptions(opts);
|
||||||
|
Reference in New Issue
Block a user