Skip to content

Commit 7c168bc

Browse files
authored
[CI-1003] setup tests and dockerfile
* add test scripts and docker * add test images,move images to test-scripts folder, add readme * set the encoding for java builds * Add Todo to fix the parse commands
1 parent c4072da commit 7c168bc

18 files changed

+619
-0
lines changed

Dockerfile

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
FROM debian:bookworm-slim AS base
3+
4+
# Build Arguments
5+
ARG ARCH
6+
ARG SDK_VERSION
7+
ARG JAVA_VERSION=17
8+
ARG SCANBOT_LICENSE
9+
10+
# Environment Variables
11+
ENV ARCH=${ARCH} \
12+
SDK_VERSION=${SDK_VERSION} \
13+
JAVA_VERSION=${JAVA_VERSION} \
14+
PYENV_ROOT="/opt/pyenv" \
15+
PATH="/opt/pyenv/bin:/opt/pyenv/shims:$PATH" \
16+
SDK_BASE_URL="https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv" \
17+
SCANBOT_LICENSE=${SCANBOT_LICENSE} \
18+
LANG=C.UTF-8 \
19+
LC_ALL=C.UTF-8
20+
21+
# Install system dependencies
22+
RUN apt-get update && apt-get install -y --no-install-recommends \
23+
# Build tools
24+
build-essential \
25+
cmake \
26+
make \
27+
libssl-dev \
28+
zlib1g-dev \
29+
libbz2-dev \
30+
libreadline-dev \
31+
libsqlite3-dev \
32+
libffi-dev \
33+
liblzma-dev \
34+
# Languages
35+
openjdk-${JAVA_VERSION}-jdk \
36+
# Utilities
37+
curl \
38+
git \
39+
ca-certificates \
40+
# Add Node.js repository and install
41+
&& curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
42+
&& apt-get install -y nodejs \
43+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
44+
45+
# Install pyenv and Python 3.6.15
46+
RUN git clone --depth=1 https://github.com/pyenv/pyenv.git $PYENV_ROOT \
47+
&& pyenv install 3.6.15 \
48+
&& pyenv global 3.6.15 \
49+
&& pyenv rehash
50+
51+
# Set JAVA_HOME
52+
RUN export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::") && \
53+
echo "JAVA_HOME=$JAVA_HOME" >> /etc/environment
54+
55+
ENV PATH="/opt/venv/bin:${PATH}"
56+
57+
# Verify Java installation
58+
RUN java -version && javac -version
59+
60+
# Set up Python packages
61+
RUN export PATH="/opt/pyenv/bin:/opt/pyenv/shims:$PATH" \
62+
&& eval "$(/opt/pyenv/bin/pyenv init -)" \
63+
&& python -m pip install --upgrade pip setuptools wheel \
64+
# The opencv-python version is specified to ensure compatibility with Python 3.6 and speed up docker builds
65+
# Once the python is upgraded to 3.7+, this can be changed to just `opencv-python`
66+
&& python -m pip install opencv-python==4.5.5.64 numpy pillow
67+
68+
# Install Python SDK
69+
RUN if [ "${ARCH}" = "linux-aarch64" ]; then \
70+
PYTHON_ARCH="linux_aarch64"; \
71+
SDK_ARCH="linux-aarch64"; \
72+
else \
73+
PYTHON_ARCH="linux_x86_64"; \
74+
SDK_ARCH="linux-x86_64"; \
75+
fi && \
76+
python -m pip install "${SDK_BASE_URL}${SDK_VERSION}/scanbotsdk-${SDK_VERSION}-py3-none-${PYTHON_ARCH}.whl" && \
77+
echo "Python SDK installed successfully"
78+
79+
# Set working directory and copy source code
80+
WORKDIR /workspaces/scanbot-sdk-example-linux
81+
COPY . .
82+
83+
# Download and install all remaining SDKs in optimal locations
84+
RUN echo "Installing Java and C SDKs for architecture: ${ARCH}" && \
85+
# Set the correct SDK architecture for downloads
86+
if [ "${ARCH}" = "linux-aarch64" ]; then \
87+
SDK_ARCH="linux-aarch64"; \
88+
else \
89+
SDK_ARCH="linux-x86_64"; \
90+
fi && \
91+
# Download platform-dependent SDKs (Java and C only)
92+
curl -L -O "${SDK_BASE_URL}${SDK_VERSION}/scanbotsdk-${SDK_VERSION}-${SDK_ARCH}.jar" && \
93+
curl -L -O "${SDK_BASE_URL}${SDK_VERSION}/scanbotsdk-${SDK_VERSION}-${SDK_ARCH}.tar.gz" && \
94+
# Install Node.js SDK (platform-independent npm package)
95+
cd examples/nodejs && \
96+
npm install "${SDK_BASE_URL}${SDK_VERSION}/nodejs-scanbotsdk-${SDK_VERSION}.tgz" && \
97+
cd /workspaces/scanbot-sdk-example-linux && \
98+
# Setup Java SDK
99+
mkdir -p examples/java/build/libs && \
100+
cp "scanbotsdk-${SDK_VERSION}-${SDK_ARCH}.jar" examples/java/build/libs/scanbotsdk.jar && \
101+
# Setup C SDK
102+
mkdir -p examples/c/build/scanbotsdk && \
103+
tar -xzf "scanbotsdk-${SDK_VERSION}-${SDK_ARCH}.tar.gz" -C examples/c/build/scanbotsdk --strip-components=1 && \
104+
# Clean up downloads
105+
rm -f *.tar.gz *.jar && \
106+
echo "All SDKs installed successfully"
107+
108+
# Copy test scripts
109+
COPY test-scripts/ /tests/
110+
RUN chmod +x /tests/*.sh
111+
112+
# SDK Verification Stage
113+
FROM base AS sdk-verification
114+
RUN echo "=== Comprehensive SDK Verification ===" \
115+
&& python -c "import scanbotsdk; print('Python SDK: Verified')" \
116+
&& cd examples/nodejs && npm install && node -e "const sdk = require('scanbotsdk'); console.log(sdk ? 'OK' : 'FAIL');" \
117+
&& cd /workspaces/scanbot-sdk-example-linux/examples/java && GRADLE_OPTS="-Dfile.encoding=UTF-8" ./gradlew check --no-daemon && echo "Java SDK: Verified" \
118+
&& cd /workspaces/scanbot-sdk-example-linux/examples/c && mkdir -p build && cd build && cmake -DSCANBOTSDK_VERSION=${SDK_VERSION} .. && make && echo "C SDK: OK"
119+
120+
# Python Tests Stage
121+
FROM sdk-verification AS python-tests
122+
RUN echo "=== Running Python Command Tests ===" \
123+
&& /tests/test-python.sh
124+
125+
# Java Tests Stage
126+
FROM sdk-verification AS java-tests
127+
RUN echo "=== Running Java Command Tests ===" \
128+
&& /tests/test-java.sh
129+
130+
# Node.js Tests Stage
131+
FROM sdk-verification AS nodejs-tests
132+
RUN echo "=== Running Node.js Command Tests ===" \
133+
&& /tests/test-nodejs.sh
134+
135+
# C Tests Stage
136+
FROM sdk-verification AS c-tests
137+
RUN echo "=== Running C Command Tests ===" \
138+
&& /tests/test-c.sh
139+
140+
# All Tests Stage
141+
FROM sdk-verification AS all-tests
142+
RUN echo "=== Running Complete Test Suite ===" \
143+
&& /tests/run-all-tests.sh \
144+
&& echo "Python import and commands verified" \
145+
&& echo "Java compilation and commands verified" \
146+
&& echo "Node.js compilation and commands verified" \
147+
&& echo "C compilation and commands verified"
148+
149+

Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ A trial license key is required for evaluation or testing. To get a free trial l
6161

6262
[Contact our team](https://scanbot.io/contact-sales/?utm_source=github.com&utm_medium=referral&utm_campaign=dev_sites) to receive your quote.
6363

64+
## Running Tests
65+
66+
The test scripts validate SDK integration, detect compilation errors, and check license issues across all supported languages (Python, Java, Node.js, C).
67+
[Detailed documentation](test-scripts/README.md)
68+
6469
## Other supported platforms
6570

6671
The Scanbot SDK is also available on Android, iOS, and most common cross-platform environments, such as React Native, Flutter, and .NET MAUI:

test-scripts/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Test Scripts
2+
3+
These test scripts validate the Scanbot SDK integration across all supported languages and detect common issues like licensing checks and compilation errors.
4+
5+
## What Tests Do
6+
7+
- **Check compilation**: Verify code builds correctly
8+
- **Validate license**: Ensure license key works
9+
- **Test commands**: Run SDK functions to catch integration issues
10+
- **Quick validation**: Fast checks for development workflow
11+
12+
**Note: No asserts are setup to validate the tests results.**
13+
14+
## Test Structure
15+
16+
```
17+
test-scripts/
18+
├── test-python.sh # Python SDK tests
19+
├── test-java.sh # Java SDK tests
20+
├── test-nodejs.sh # Node.js SDK tests
21+
├── test-c.sh # C SDK tests
22+
├── run-all-tests.sh # Run all tests
23+
└── test-images/ # Test image files
24+
```
25+
26+
## Running Tests
27+
28+
### 1. Build Test Container
29+
30+
```bash
31+
docker build \
32+
--build-arg SDK_VERSION=0.800.3 \
33+
--build-arg ARCH=linux-aarch64 \
34+
--build-arg SCANBOT_LICENSE=$SCANBOT_LICENSE \
35+
--target sdk-verification \
36+
-t scanbot-test .
37+
```
38+
39+
### 2. Set License Key
40+
41+
```bash
42+
export SCANBOT_LICENSE="your-license-key-here"
43+
```
44+
45+
### 3. Run Tests
46+
47+
**Single test:**
48+
```bash
49+
docker run --rm \
50+
--env SCANBOT_LICENSE=$SCANBOT_LICENSE \
51+
--workdir /workspaces/scanbot-sdk-example-linux \
52+
scanbot-test \
53+
/tests/test-python.sh
54+
```
55+
56+
**All tests:**
57+
```bash
58+
docker run --rm \
59+
--env SCANBOT_LICENSE=$SCANBOT_LICENSE \
60+
--workdir /workspaces/scanbot-sdk-example-linux \
61+
scanbot-test \
62+
/tests/run-all-tests.sh
63+
```
64+
65+
## Test Commands
66+
67+
Each test validates these SDK functions:
68+
69+
- **Barcode scanning** - QR codes, barcodes
70+
- **Document scanning** - Document detection
71+
- **Data extraction** - Credit cards, checks, MRZ, VIN
72+
- **OCR** - Text recognition
73+
- **Document analysis** - Multi-page, cropping
74+
- **Text parsing** - MRZ, barcode document parsing

test-scripts/run-all-tests.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "========================================"
5+
echo " Scanbot SDK - Full Test Suite"
6+
echo "========================================"
7+
8+
# Track test results
9+
FAILED_TESTS=""
10+
TOTAL_TESTS=0
11+
PASSED_TESTS=0
12+
13+
run_test() {
14+
local test_name="$1"
15+
local test_script="$2"
16+
17+
echo ""
18+
echo "Running $test_name tests..."
19+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
20+
21+
if bash "$test_script"; then
22+
echo "PASS: $test_name tests PASSED"
23+
PASSED_TESTS=$((PASSED_TESTS + 1))
24+
else
25+
echo "$test_name tests FAILED"
26+
FAILED_TESTS="$FAILED_TESTS $test_name"
27+
fi
28+
}
29+
30+
# Run all test suites
31+
run_test "Python" "/tests/test-python.sh"
32+
run_test "Java" "/tests/test-java.sh"
33+
run_test "Node.js" "/tests/test-nodejs.sh"
34+
run_test "C" "/tests/test-c.sh"
35+
36+
# Final report
37+
echo ""
38+
echo "========================================"
39+
echo " Test Summary"
40+
echo "========================================"
41+
echo "Total test suites: $TOTAL_TESTS"
42+
echo "Passed: $PASSED_TESTS"
43+
echo "Failed: $((TOTAL_TESTS - PASSED_TESTS))"
44+
45+
if [ $PASSED_TESTS -eq $TOTAL_TESTS ]; then
46+
echo ""
47+
echo "ALL TESTS PASSED!"
48+
echo "Scanbot SDK is working correctly across all platforms."
49+
exit 0
50+
else
51+
echo ""
52+
echo "Some tests failed:"
53+
echo "$FAILED_TESTS"
54+
echo ""
55+
echo "Please check the logs above for details."
56+
exit 1
57+
fi

test-scripts/test-c.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=== C SDK Command Tests ==="
5+
6+
# Find the project root directory
7+
if [[ -d "/workspaces/scanbot-sdk-example-linux/examples/c" ]]; then
8+
cd /workspaces/scanbot-sdk-example-linux/examples/c
9+
elif [[ -d "examples/c" ]]; then
10+
cd examples/c
11+
else
12+
echo "ERROR: Cannot find C examples directory"
13+
exit 1
14+
fi
15+
16+
echo "Testing executable exists..."
17+
if [[ -x "./build/scanbotsdk_example" ]]; then
18+
echo "PASS: C executable: EXISTS"
19+
ls -la build/scanbotsdk_example
20+
else
21+
echo "FAIL: C executable: NOT FOUND"
22+
echo "Looking for executable in current directory:"
23+
ls -la
24+
echo "Looking for executable in build directory:"
25+
ls -la build/ || echo "Build directory not found"
26+
exit 1
27+
fi
28+
29+
# Check if license is available
30+
if [[ -z "${SCANBOT_LICENSE}" ]]; then
31+
echo "ERROR: No license available"
32+
echo "SCANBOT_LICENSE environment variable is not set"
33+
echo "Tests cannot run without a valid license"
34+
exit 1
35+
fi
36+
37+
echo "Testing SCAN commands..."
38+
commands=(
39+
"scan barcode --file ../../test-scripts/test-images/qrcode.jpeg --license \"${SCANBOT_LICENSE}\""
40+
"scan document --file ../../test-scripts/test-images/Document.jpeg --license \"${SCANBOT_LICENSE}\""
41+
"scan check --file ../../test-scripts/test-images/check.jpeg --license \"${SCANBOT_LICENSE}\""
42+
"scan credit_card --file ../../test-scripts/test-images/credit_card.jpeg --license \"${SCANBOT_LICENSE}\""
43+
"scan document_extractor --file ../../test-scripts/test-images/EHIC.jpeg --license \"${SCANBOT_LICENSE}\""
44+
"scan medical_certificate --file ../../test-scripts/test-images/medical_certificate.jpeg --license \"${SCANBOT_LICENSE}\""
45+
"scan mrz --file ../../test-scripts/test-images/MRZ_passport.jpeg --license \"${SCANBOT_LICENSE}\""
46+
"scan ocr --file ../../test-scripts/test-images/Document.jpeg --license \"${SCANBOT_LICENSE}\""
47+
"scan text_pattern --file ../../test-scripts/test-images/Document.jpeg --license \"${SCANBOT_LICENSE}\""
48+
"scan vin --file ../../test-scripts/test-images/VIN.jpeg --license \"${SCANBOT_LICENSE}\""
49+
"classify document --file ../../test-scripts/test-images/toll_receipt.jpeg --license \"${SCANBOT_LICENSE}\""
50+
"analyze analyze_multi_page --file ../../test-scripts/test-images/multi_page_document.pdf --license \"${SCANBOT_LICENSE}\""
51+
"analyze crop_analyze --file ../../test-scripts/test-images/Document.jpeg --license \"${SCANBOT_LICENSE}\""
52+
# TODO: Fix C SDK parse test,which currently returns success 0 only in tests
53+
"parse mrz --text \"P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<L898902C36UTO7408122F1204159ZE184226B<<<<<10\" --license \"${SCANBOT_LICENSE}\""
54+
"parse barcode_doc --text \"(01)03453120000011(17)191125(10)ABCD1234\" --license \"${SCANBOT_LICENSE}\""
55+
)
56+
57+
command_names=(
58+
"Barcode scan"
59+
"Document scan"
60+
"Check scan"
61+
"Credit card scan"
62+
"Document extractor scan"
63+
"Medical certificate scan"
64+
"MRZ scan"
65+
"OCR scan"
66+
"Text pattern scan"
67+
"VIN scan"
68+
"Document classify"
69+
"Multi-page analyze"
70+
"Crop analyze"
71+
"MRZ parse"
72+
"Barcode document parse"
73+
)
74+
75+
for i in "${!commands[@]}"; do
76+
cmd="${commands[$i]}"
77+
name="${command_names[$i]}"
78+
79+
if timeout 30 ./build/scanbotsdk_example $cmd; then
80+
echo "PASS: $name: PASSED"
81+
elif [[ $? -eq 124 ]]; then
82+
echo "FAIL: $name: TIMEOUT"
83+
exit 1
84+
else
85+
echo "FAIL: $name: FAILED"
86+
exit 1
87+
fi
88+
done
89+
90+
echo "PASS: C tests PASSED"
91+
523 KB
Loading

test-scripts/test-images/EHIC.jpeg

80.4 KB
Loading
458 KB
Loading

test-scripts/test-images/VIN.jpeg

28.8 KB
Loading
232 KB
Loading

0 commit comments

Comments
 (0)