+++ /dev/null
-//
-// Created by v.cherepanov on 28.03.18.
-//
-
-#ifndef __BASEEXCEPTION_H__
-#define __BASEEXCEPTION_H__
-
-#include <vector>
-#include <string>
-#include <ostream>
-
-namespace nncc
-{
-namespace foundation
-{
-
-class Exception : public std::exception
-{
-public:
- Exception() = default;
- ~Exception() throw() override = default;
-
- explicit Exception(const std::string &info);
- explicit Exception(Exception &e, const std::string &info);
-
- Exception &append(const std::string &info);
- const std::vector<std::string> &getInfo() const;
- const char *what() const throw() override;
-
-private:
- std::vector<std::string> _info;
- mutable std::string _sInfo;
-};
-
-std::ostream &operator<<(std::ostream &s, const Exception &e);
-
-} // namespace foundation
-} // namespace nncc
-
-#endif // __BASEEXCEPTION_H__
+++ /dev/null
-//
-// Created by v.cherepanov@samsung.com on 28.03.18.
-//
-
-#include <string>
-#include <iostream>
-#include <stdexcept>
-
-#include "nncc/foundation/Exception.h"
-
-namespace nncc
-{
-namespace foundation
-{
-
-Exception::Exception(const std::string &info) { _info.push_back(info); }
-
-Exception::Exception(Exception &e, const std::string &info)
-{
- for (auto errors : e.getInfo())
- {
- _info.push_back(errors);
- }
- _info.push_back(info);
-}
-
-const char *Exception::what() const throw()
-{
- _sInfo.clear();
- for (auto it : _info)
- _sInfo.append(it).append("\n");
- return _sInfo.c_str();
-}
-
-const std::vector<std::string> &Exception::getInfo() const { return _info; }
-
-Exception &Exception::append(const std::string &info)
-{
- _info.push_back(info);
- return *this;
-}
-
-std::ostream &operator<<(std::ostream &s, const Exception &e)
-{
- for (auto &errors : e.getInfo())
- {
- s << errors << std::endl;
- }
- return s;
-}
-
-} // namespace foundation
-} // namespace nncc
+++ /dev/null
-#include <nncc/foundation/Exception.h>
-
-#include <gtest/gtest.h>
-
-using namespace nncc::foundation;
-
-std::string errorMsg1 = "error constructor";
-std::string errorMsg2 = "error append";
-std::string errorMsg3 = "error second constructor";
-
-std::vector<std::string> msgs = {errorMsg1, errorMsg2, errorMsg3};
-
-void err1() { throw Exception(errorMsg1); }
-
-void err2()
-{
- try
- {
- err1();
- }
- catch (Exception &e)
- {
- throw e.append(errorMsg2);
- }
-}
-
-void err3()
-{
- try
- {
- err2();
- }
- catch (Exception &e)
- {
- throw Exception(e, errorMsg3);
- }
-}
-
-TEST(FOUNDATION_EXCEPTION, Exception)
-{
- try
- {
- err3();
- }
- catch (Exception &e)
- {
- ASSERT_TRUE(msgs == e.getInfo());
-
- std::string glued;
- const char delim[] = "\n";
- glued.append(errorMsg1).append(delim);
- glued.append(errorMsg2).append(delim);
- glued.append(errorMsg3).append(delim);
- ASSERT_TRUE(glued == e.what());
- return;
- }
-
- // should not be happened
- ASSERT_TRUE(false);
-}