Skip to content

Commit 8246fd6

Browse files
committed
fixing Calculator, UnitTest, Prime examples
1 parent abfb3ec commit 8246fd6

File tree

105 files changed

+1497
-1147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1497
-1147
lines changed

Build/Dockerfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,27 @@ RUN rpm --import https://download.mono-project.com/repo/xamarin.gpg \
4242
&& dnf config-manager --add-repo https://download.mono-project.com/repo/centos8-stable.repo \
4343
&& dnf -y install mono-complete
4444

45-
# General tools
46-
RUN dnf -y install glibc-common glibc-utils less passwd tar vim-minimal vim-enhanced which sudo bash-completion mc yum-utils && yum clean all
45+
# .NET
46+
RUN dnf -y install wget \
47+
&& wget https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm \
48+
&& rpm -Uvh packages-microsoft-prod.rpm \
49+
&& dnf -y install dotnet-sdk-6.0
50+
51+
# General purpose tools
52+
RUN dnf -y install \
53+
glibc-common \
54+
glibc-utils \
55+
less \
56+
passwd \
57+
tar \
58+
vim-minimal \
59+
vim-enhanced \
60+
which \
61+
sudo \
62+
bash-completion \
63+
mc \
64+
yum-utils \
65+
&& yum clean all
4766

4867
# Enable GCC toolset in shells
4968
RUN echo "source /opt/rh/gcc-toolset-9/enable" >> /etc/bashrc

Examples/Calculator/Calculator_component/Bindings/CppDynamic/calculator_abi.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright (C) 2019 Calculator developers
44
55
All rights reserved.
66
7-
This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0.
7+
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
88
99
Abstract: This is an autogenerated C++-Header file in order to allow an easy
1010
use of Calculator library
@@ -29,12 +29,23 @@ Interface version: 1.0.0
2929
#include "calculator_types.hpp"
3030

3131

32+
#ifdef __cplusplus
3233
extern "C" {
34+
#endif
3335

3436
/*************************************************************************************************************************
3537
Class definition for Base
3638
**************************************************************************************************************************/
3739

40+
/**
41+
* Get Class Type Id
42+
*
43+
* @param[in] pBase - Base instance.
44+
* @param[out] pClassTypeId - Class type as a 64 bits integer
45+
* @return error code or 0 (success)
46+
*/
47+
CALCULATOR_DECLSPEC CalculatorResult calculator_base_classtypeid(Calculator_Base pBase, Calculator_uint64 * pClassTypeId);
48+
3849
/*************************************************************************************************************************
3950
Class definition for Variable
4051
**************************************************************************************************************************/
@@ -165,7 +176,9 @@ CALCULATOR_DECLSPEC CalculatorResult calculator_createvariable(Calculator_double
165176
*/
166177
CALCULATOR_DECLSPEC CalculatorResult calculator_createcalculator(Calculator_Calculator * pInstance);
167178

179+
#ifdef __cplusplus
168180
}
181+
#endif
169182

170183
#endif // __CALCULATOR_HEADER_CPP
171184

Examples/Calculator/Calculator_component/Examples/CppDynamic/build.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,20 @@ pushd build
1313
cmake -H.. -B. -DCMAKE_BUILD_TYPE=Debug
1414
cmake --build .
1515

16+
echo "List C++ library"
17+
ls ../../../Implementations/Cpp/build
18+
1619
echo "Test C++ library"
1720
RUN ./CalculatorExample_CPPDynamic ../../../Implementations/Cpp/build
1821

22+
echo "List Pascal library"
23+
ls ../../../Implementations/Pascal/build
24+
1925
echo "Test Pascal library"
20-
RUN ./CalculatorExample_CPPDynamic ../../../Implementations/Pascal/build
26+
if [ -f "../../../Implementations/Pascal/build/calculator$OSLIBEXT" ]; then
27+
RUN ./CalculatorExample_CPPDynamic ../../../Implementations/Pascal/build
28+
else
29+
echo "Pascal library not found - skipping Pascal test (normal if fpc not available)"
30+
fi
2131

2232
popd

Examples/Calculator/Calculator_component/Examples/Pascal/Calculator_Example.lpr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*)
1515

1616
program CalculatorPascalTest;
17+
{$mode objfpc}{$H+}
1718

1819
uses
1920
{$IFDEF UNIX}{$IFDEF UseCThreads}

Examples/Calculator/Calculator_component/Examples/Pascal/build.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ fpc -Fu../../Bindings/Pascal -FU./build -o./build/Calculator_Example$OSEXEEXT Ca
1313
pushd build
1414

1515
echo "Test C++ library"
16-
rm -f calculator.dll
17-
ln -s ../../../Implementations/Cpp/build/calculator$OSLIBEXT calculator.dll
18-
RUN ./Calculator_Example .
16+
if [ -f "../../../Implementations/Cpp/build/calculator$OSLIBEXT" ]; then
17+
rm -f calculator.dll
18+
ln -s ../../../Implementations/Cpp/build/calculator$OSLIBEXT calculator.dll
19+
RUN ./Calculator_Example .
20+
else
21+
echo "C++ library not found - skipping C++ test"
22+
fi
1923

2024
echo "Test Pascal library"
21-
rm -f calculator.dll
22-
ln -s ../../../Implementations/Pascal/build/calculator$OSLIBEXT calculator.dll
23-
RUN ./Calculator_Example .
25+
if [ -f "../../../Implementations/Pascal/build/calculator$OSLIBEXT" ]; then
26+
rm -f calculator.dll
27+
ln -s ../../../Implementations/Pascal/build/calculator$OSLIBEXT calculator.dll
28+
RUN ./Calculator_Example .
29+
else
30+
echo "Pascal library not found - skipping Pascal test (normal if fpc not available)"
31+
fi
2432

2533
popd

Examples/Calculator/Calculator_component/Examples/Python/build.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ set -euxo pipefail
55
cd "$(dirname "$0")"
66
source ../../../../../Build/build.inc
77

8-
echo "Test with available libraries"
9-
if [ -d "$PWD/../../Implementations/Cpp/build" ] && [ -f "$PWD/../../Implementations/Cpp/build/calculator$OSLIBEXT" ]; then
8+
echo "Test with C++ library"
9+
if [ -f "$PWD/../../Implementations/Cpp/build/calculator$OSLIBEXT" ]; then
1010
echo "Testing with C++ library"
1111
RUN "python3 Calculator_Example.py" $PWD/../../Implementations/Cpp/build
12-
elif [ -d "$PWD/../../Implementations/Pascal/build" ] && [ -f "$PWD/../../Implementations/Pascal/build/calculator$OSLIBEXT" ]; then
12+
else
13+
echo "C++ library not found - skipping C++ test"
14+
fi
15+
16+
echo "Test with Pascal library"
17+
if [ -f "$PWD/../../Implementations/Pascal/build/calculator$OSLIBEXT" ]; then
1318
echo "Testing with Pascal library"
1419
RUN "python3 Calculator_Example.py" $PWD/../../Implementations/Pascal/build
1520
else
16-
echo "No library found - skipping Python test (this is normal if no implementations were built)"
21+
echo "Pascal library not found - skipping Pascal test (normal if fpc not available)"
1722
fi

Examples/Calculator/Calculator_component/Implementations/Pascal/Interfaces/calculator.lpr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
All rights reserved.
66
7-
This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0.
7+
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
88
99
Abstract: This is an autogenerated Pascal project file in order to allow easy
1010
development of Calculator library.
@@ -27,6 +27,7 @@
2727
sysutils;
2828

2929
exports
30+
calculator_base_classtypeid,
3031
calculator_variable_getvalue,
3132
calculator_variable_setvalue,
3233
calculator_calculator_enlistvariable,
@@ -41,6 +42,10 @@
4142
calculator_createvariable,
4243
calculator_createcalculator;
4344

45+
{$IFDEF CALCULATOR_INCLUDE_RES_FILE}
46+
{$R *.res}
47+
{$ENDIF CALCULATOR_INCLUDE_RES_FILE}
48+
4449
begin
4550

4651
end.

Examples/Calculator/Calculator_component/Implementations/Pascal/Interfaces/calculator_interfaces.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface
3232
**************************************************************************************************************************)
3333

3434
ICalculatorBase = interface
35-
['{606128A4-C847-4057-A841-4B8871165F63}']
35+
['{C214B605-F0FB-481A-BD3E-3CFF478EF3C5}']
3636

3737
function GetLastErrorMessage(out AErrorMessage: String): Boolean;
3838
procedure ClearErrorMessages();
@@ -48,7 +48,7 @@ interface
4848
**************************************************************************************************************************)
4949

5050
ICalculatorVariable = interface(ICalculatorBase)
51-
['{1E683C18-EFC4-4772-AB4B-6A055D74C97F}']
51+
['{5C7138D7-DD48-4F7A-9888-FBF2998C807F}']
5252

5353
function GetValue(): Double;
5454
procedure SetValue(const AValue: Double);
@@ -60,7 +60,7 @@ interface
6060
**************************************************************************************************************************)
6161

6262
ICalculatorCalculator = interface(ICalculatorBase)
63-
['{65CB20D4-1384-4F17-BB4D-0F556E2EA955}']
63+
['{665BE1D3-F168-4479-AB9D-173D25300D09}']
6464

6565
procedure EnlistVariable(AVariable: TObject);
6666
function GetEnlistedVariable(const AIndex: Cardinal): TObject;

Examples/Calculator/Calculator_component/Implementations/Pascal/Stub/calculator_impl.pas

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
All rights reserved.
66
7-
This file has been generated by the Automatic Component Toolkit (ACT) version 1.6.0.
7+
This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.
88
99
Abstract: This is an autogenerated Pascal implementation file in order to allow easy
1010
development of Calculator library. It needs to be generated only once.
@@ -22,13 +22,14 @@ interface
2222
calculator_types,
2323
calculator_exception,
2424
calculator_interfaces,
25+
calculator_impl_base,
2526
calculator_impl_variable,
2627
calculator_impl_calculator,
2728
Classes,
2829
sysutils;
2930

3031
type
31-
TCalculatorWrapper = class (TObject)
32+
TCalculatorWrapper = class(TObject)
3233
public
3334
class procedure GetVersion(out AMajor: Cardinal; out AMinor: Cardinal; out AMicro: Cardinal);
3435
class function GetLastError(AInstance: TObject; out AErrorMessage: String): Boolean;
@@ -50,28 +51,35 @@ class procedure TCalculatorWrapper.GetVersion(out AMajor: Cardinal; out AMinor:
5051

5152
class function TCalculatorWrapper.GetLastError(AInstance: TObject; out AErrorMessage: String): Boolean;
5253
begin
53-
result := (AInstance as ICalculatorBase).GetLastErrorMessage(AErrorMessage);
54+
if Assigned(AInstance) and (AInstance is TCalculatorBase) then
55+
begin
56+
Result := (AInstance as TCalculatorBase).GetLastErrorMessage(AErrorMessage);
57+
end
58+
else
59+
begin
60+
AErrorMessage := '';
61+
Result := False;
62+
end;
5463
end;
5564

5665
class procedure TCalculatorWrapper.ReleaseInstance(AInstance: TObject);
5766
begin
58-
(AInstance as ICalculatorBase).DecRefCount();
67+
(AInstance as ICalculatorBase).DecRefCount();
5968
end;
6069

6170
class procedure TCalculatorWrapper.AcquireInstance(AInstance: TObject);
6271
begin
63-
(AInstance as ICalculatorBase).IncRefCount();
72+
(AInstance as ICalculatorBase).IncRefCount();
6473
end;
6574

6675
class function TCalculatorWrapper.CreateVariable(const AInitialValue: Double): TObject;
6776
begin
68-
result := TCalculatorVariable.Create();
69-
(result as TCalculatorVariable).SetValue(AInitialValue);
77+
Result := TCalculatorVariable.Create(AInitialValue);
7078
end;
7179

7280
class function TCalculatorWrapper.CreateCalculator(): TObject;
7381
begin
74-
result := TCalculatorCalculator.Create();
82+
Result := TCalculatorCalculator.Create();
7583
end;
7684

7785

Examples/Calculator/Calculator_component/Implementations/Pascal/Stub/calculator_impl_base.pas

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TCalculatorBase = class(TObject, ICalculatorBase)
3636
procedure RegisterErrorMessage(const AErrorMessage: String);
3737
procedure IncRefCount();
3838
function DecRefCount(): Boolean;
39-
function ClassTypeId(): QWord; virtual;
39+
function ClassTypeId(): QWord; Virtual; Abstract;
4040
end;
4141

4242
implementation
@@ -68,7 +68,6 @@ procedure TCalculatorBase.ClearErrorMessages();
6868

6969
procedure TCalculatorBase.RegisterErrorMessage(const AErrorMessage: String);
7070
begin
71-
FMessages.Clear();
7271
FMessages.Add(AErrorMessage);
7372
end;
7473

@@ -79,17 +78,18 @@ procedure TCalculatorBase.IncRefCount();
7978

8079
function TCalculatorBase.DecRefCount(): Boolean;
8180
begin
82-
dec(FReferenceCount);
83-
if (FReferenceCount = 0) then begin
84-
result := true;
85-
self.Destroy();
86-
end;
87-
result := false;
88-
end;
89-
90-
function TCalculatorBase.ClassTypeId(): QWord;
91-
begin
92-
result := 0; // Base class type ID
81+
if (FReferenceCount > 0) then
82+
begin
83+
dec(FReferenceCount);
84+
if (FReferenceCount = 0) then begin
85+
self.Destroy();
86+
result := true;
87+
end
88+
else
89+
result := false;
90+
end
91+
else
92+
result := false; // Already at 0, don't double-destroy
9393
end;
9494

9595
end.

0 commit comments

Comments
 (0)