#!/bin/bash
set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" EXIT
cd "$WORKDIR"

echo "Testing lmdbxx compilation..."

cat > test_compile.cpp << 'CPPEOF'
#include <lmdb++.h>
#include <iostream>

int main() {
    std::cout << "lmdbxx compilation test" << std::endl;
    
    // Test basic types
    lmdb::env env = lmdb::env::create();
    
    std::cout << "✓ lmdbxx headers work correctly" << std::endl;
    return 0;
}
CPPEOF

echo "Compiling test program..."
g++ -std=c++17 test_compile.cpp -o test_compile -llmdb "${LMDBXX_FLAGS[@]}"

if [ -f test_compile ]; then
    echo "✓ Compilation successful"
    ./test_compile
    ret=$?
    rm -f test_compile test_compile.cpp
    echo "✓ Test passed"
    exit $ret
else
    echo "✗ Compilation failed"
    exit 1
fi
