Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
akawashiro committed Jul 24, 2024
1 parent 51f5a15 commit ed9f406
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
15 changes: 15 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/fuga.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "fuga.h"

struct CustomException {};

void throw_exception_fuga() {
throw CustomException();
}

void catch_exception_fuga() {
try {
throw_exception_fuga();
} catch (CustomException) {
std::cerr << "Caught CustomException" << std::endl;
}
}
6 changes: 6 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/fuga.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <exception>
#include <iostream>
#include <stdexcept>

void throw_exception_fuga();
void catch_exception_fuga();
20 changes: 20 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/hoge.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "hoge.h"
#include "fuga.h"

void throw_exception_hoge() {
throw std::runtime_error("hoge from throw_exception_hoge");
}

void catch_exception_hoge() {
try {
throw_exception_hoge();
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}

try {
throw_exception_fuga();
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}
6 changes: 6 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/hoge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <exception>
#include <iostream>
#include <stdexcept>

void throw_exception_hoge();
void catch_exception_hoge();
13 changes: 13 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "hoge.h"

int main() {
std::cout << "catch_exception" << std::endl;
catch_exception_hoge();

std::cout << "throw_exception" << std::endl;
try {
throw_exception_hoge();
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}
13 changes: 13 additions & 0 deletions feature_unit_tests/user-defined-exception-g++/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /bin/bash -eu

g++ -fPIC -shared -o libfuga.so -Wl,-soname,libfuga.so fuga.cc
g++ -fPIC -shared -o libhoge.so.original -Wl,-soname,libhoge.so hoge.cc libfuga.so
g++ main.cc -o main.out libhoge.so.original libfuga.so
LD_LIBRARY_PATH=. $(git rev-parse --show-toplevel)/build/sold -i libhoge.so.original -o libhoge.so.soldout --section-headers --check-output

# Use sold
ln -sf libhoge.so.soldout libhoge.so
# Use original
ln -sf libhoge.so.original libhoge.so

LD_LIBRARY_PATH=. ./main.out

0 comments on commit ed9f406

Please sign in to comment.