Skip to content

Commit 08570f4

Browse files
committed
Add test of issue #69
1 parent fce957f commit 08570f4

File tree

8 files changed

+110
-6
lines changed

8 files changed

+110
-6
lines changed

.github/workflows/test-linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ jobs:
4848
rm -f /opt/hostedtoolcache/julia/1.6*/x64/lib/julia/libstdc++.so.6
4949
fi
5050
if [ "$RUNNER_OS" = Linux ]; then
51-
cmake -DClang_DIR=/usr/lib/llvm-13/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
51+
cmake -DClang_DIR=/usr/lib/llvm-19/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
5252
cmake --build build --verbose -j `nproc`
5353
else
54-
cmake -DClang_DIR=/opt/homebrew/opt/llvm@13/lib/cmake/clang -B build -S .
54+
cmake -DClang_DIR=/opt/homebrew/opt/llvm@19/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
5555
cmake --build build --verbose -j `sysctl -n hw.logicalcpu`
5656
fi
5757
cmake --install build

.github/workflows/test-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
# - ubuntu-latest
2323
- macOS-latest
2424
arch:
25-
- x64
25+
- aarch64
2626
steps:
2727
- uses: actions/checkout@v3
2828
with:
@@ -48,10 +48,10 @@ jobs:
4848
rm -f /opt/hostedtoolcache/julia/1.6*/x64/lib/julia/libstdc++.so.6
4949
fi
5050
if [ "$RUNNER_OS" = Linux ]; then
51-
cmake -DClang_DIR=/usr/lib/llvm-13/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
51+
cmake -DClang_DIR=/usr/lib/llvm-19/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
5252
cmake --build build --verbose -j `nproc`
5353
else
54-
cmake -DClang_DIR=/opt/homebrew/opt/llvm@13/lib/cmake/clang -B build -S .
54+
cmake -DClang_DIR=/opt/homebrew/opt/llvm@19/lib/cmake/clang -DCMAKE_INSTALL_PREFIX="$PWD" -B build -S .
5555
cmake --build build --verbose -j `sysctl -n hw.logicalcpu`
5656
fi
5757
cmake --install build

test/TestAbstractClass/A.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef A_H
2+
#define A_H
3+
4+
#include <string>
5+
6+
struct G4ThreeVector
7+
{
8+
G4ThreeVector(double x, double y, double z) : x(x), y(y), z(z) {}
9+
double x, y, z;
10+
};
11+
12+
struct G4VSolid // Pure abstract class
13+
{
14+
G4VSolid(const std::string& name) { fshapeName = name; }
15+
virtual ~G4VSolid() {}
16+
virtual bool Inside(const G4ThreeVector& p) const = 0;
17+
std::string fshapeName;
18+
};
19+
20+
struct G4BooleanSolid : public G4VSolid // also abstract class because it does not implement Inside()
21+
{
22+
G4BooleanSolid( const std::string& pName, G4VSolid* pSolidA , G4VSolid* pSolidB) : G4VSolid(pName), fSolidA(pSolidA), fSolidB(pSolidB) {}
23+
virtual ~G4BooleanSolid() {}
24+
G4VSolid* fSolidA;
25+
G4VSolid* fSolidB;
26+
};
27+
28+
struct G4UnionSolid : public G4BooleanSolid // concrete class
29+
{
30+
G4UnionSolid( const std::string& pName, G4VSolid* pSolidA, G4VSolid* pSolidB) : G4BooleanSolid(pName, pSolidA, pSolidB) {}
31+
virtual ~G4UnionSolid() {}
32+
bool Inside(const G4ThreeVector& p) const override { return fSolidA->Inside(p) || fSolidB->Inside(p);}
33+
};
34+
35+
struct G4Box : public G4VSolid // concrete class
36+
{
37+
G4Box(const std::string& name, double x, double y, double z) : G4VSolid(name), fX(x), fY(y), fZ(z) {}
38+
virtual ~G4Box() {}
39+
bool Inside(const G4ThreeVector& p) const override { return p.x < fX && p.y < fY && p.z < fZ; }
40+
double fX, fY, fZ;
41+
};
42+
43+
#endif //A_H not defined
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(TestAbstractClass)
4+
5+
# All of the real work is done in the lower level CMake file
6+
include(../WrapitTestSetup.cmake)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module_name = "TestAbstractClass"
2+
uuid = "418a21d6-7439-4776-b194-a2b4eefa9b4a"
3+
4+
include_dirs = [ "." ]
5+
6+
input = [ "A.h" ]
7+
8+
#extra_input = [ "cstdef" ]
9+
10+
cxx-std = "c++17"
11+
12+
export = "all"
13+
14+
auto_veto = true
15+
16+
# all generated code in a single file:
17+
n_classes_per_file = 0
18+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env julia
2+
3+
TEST_SCRIPT="runTestAbstractClass.jl"
4+
5+
#number of cores to use for code compilation
6+
ncores=Sys.CPU_THREADS
7+
8+
# Generate the wrapper and build the shared library:
9+
run(`cmake -B build .`)
10+
run(`cmake --build build -j $ncores`)
11+
12+
# Execute the test
13+
include(TEST_SCRIPT)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Test
2+
using Serialization
3+
4+
import Pkg
5+
Pkg.activate("$(@__DIR__)/build")
6+
Pkg.develop(path="$(@__DIR__)/build/TestAbstractClass")
7+
using TestAbstractClass
8+
9+
function runtest()
10+
@testset "Abstract Class" begin
11+
box = G4Box("box", 10., 10., 10.)
12+
vec1 = G4ThreeVector(5., 5., 5.)
13+
vec2 = G4ThreeVector(0., 0., 20.)
14+
@test Inside(box, vec1)
15+
@test !Inside(box, vec2)
16+
end
17+
end
18+
19+
if "-s" in ARGS #Serialize mode
20+
Test.TESTSET_PRINT_ENABLE[] = false
21+
serialize(stdout, runtest())
22+
else
23+
runtest()
24+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Serialization
55
tests = [ "TestSizet", "TestCtorDefVal", "TestAccessAndDelete", "TestNoFinalizer", "TestInheritance",
66
"TestPropagation", "TestTemplate1", "TestTemplate2", "TestVarField", "TestStdString", "TestStringView",
77
"TestStdVector", "TestOperators", "TestEnum", "TestPointers", "TestEmptyClass", "TestUsingType", "TestNamespace",
8-
"TestOrder", "TestAutoAdd"
8+
"TestOrder", "TestAutoAdd", "TestAbstractClass"
99
]
1010

1111
# Switch to test examples

0 commit comments

Comments
 (0)