proofmode 0.9.0

Capture, share, and preserve verifiable photos and videos
Documentation
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'test/unit'
require 'tempfile'
require 'tmpdir'
require_relative '../lib/proofmode'

class TestProofModeUniFFI < Test::Unit::TestCase
  def setup
    @storage_path = Dir.mktmpdir
    @test_email = "test@example.com"
    @test_passphrase = "test_passphrase"
  end

  def teardown
    FileUtils.rm_rf(@storage_path) if Dir.exist?(@storage_path)
  end

  def test_version
    version = ProofMode.version
    assert_equal "0.4.0", version
  end

  def test_get_proofmode_version
    version = ProofMode.get_proofmode_version
    assert_equal "0.4.0", version
  end

  def test_create_proofmode
    pm = ProofMode.create_proofmode(@storage_path, @test_email, @test_passphrase)
    assert_not_nil pm
  end

  def test_generator_class
    generator = ProofMode::Generator.new(
      storage_path: @storage_path,
      email: @test_email,
      passphrase: @test_passphrase
    )
    
    # Test version
    version = generator.version
    assert_equal "0.4.0", version
  end

  def test_checker_class
    checker = ProofMode::Checker.new
    assert_not_nil checker
  end

  def test_progress_callback
    messages = []
    
    callback = ProofMode::SimpleProgressCallback.new
    # Override the report_progress method to capture messages
    def callback.report_progress(message)
      @messages ||= []
      @messages << message
    end
    
    def callback.messages
      @messages || []
    end
    
    callback.report_progress("Test message")
    # Note: Since SimpleProgressCallback prints to stdout, we can't easily test the output
    # This test mainly ensures the callback can be created and called
    assert_not_nil callback
  end

  def test_platform_callbacks
    callbacks = ProofMode::SimplePlatformCallbacks.new(@storage_path)
    
    # Test device info
    device_info = callbacks.get_device_info
    assert_not_nil device_info
    assert_equal "Ruby", device_info.manufacturer
    
    # Test network info
    network_info = callbacks.get_network_info
    assert_not_nil network_info
    assert_equal "unknown", network_info.network_type
    
    # Test location (should return nil)
    location = callbacks.get_location
    assert_nil location
  end

  def test_generate_proof_simple
    # Create a test file
    temp_file = File.join(@storage_path, "test.txt")
    File.write(temp_file, "Test content")
    
    # Generate proof
    proof_hash = ProofMode.generate_proof_simple(
      temp_file,
      storage_path: @storage_path,
      email: @test_email,
      passphrase: @test_passphrase,
      metadata: { "description" => "Test file" }
    )
    
    assert_not_nil proof_hash
    assert_instance_of String, proof_hash
  end

  def test_check_files_simple
    # Create a test file
    temp_file = File.join(@storage_path, "test.txt")
    File.write(temp_file, "Test content")
    
    # Check files
    result = ProofMode.check_files_simple([temp_file])
    
    assert_not_nil result
    assert_instance_of String, result
    
    # Result should be valid JSON
    require 'json'
    parsed_result = JSON.parse(result)
    assert parsed_result.key?("metadata")
    assert parsed_result["metadata"].key?("version")
  end

  def test_data_structures
    # Test ProofModeConfig
    config = ProofMode::ProofModeConfig.new(@storage_path, @test_email, @test_passphrase)
    assert_equal @storage_path, config.storage_path
    assert_equal @test_email, config.email
    assert_equal @test_passphrase, config.passphrase
    
    # Test LocationInfo
    location = ProofMode::LocationInfo.new(37.7749, -122.4194, 100.0, 10.0, "GPS")
    assert_equal 37.7749, location.latitude
    assert_equal(-122.4194, location.longitude)
    assert_equal 100.0, location.altitude
    assert_equal 10.0, location.accuracy
    assert_equal "GPS", location.provider
    
    # Test DeviceInfo
    device = ProofMode::DeviceInfo.new("Test", "TestModel", "TestOS 1.0", "test123", "123456789")
    assert_equal "Test", device.manufacturer
    assert_equal "TestModel", device.model
    assert_equal "TestOS 1.0", device.os_version
    assert_equal "test123", device.device_id
    assert_equal "123456789", device.imei
    
    # Test NetworkInfo
    network = ProofMode::NetworkInfo.new("WiFi", "TestCarrier", "tower123", "TestNetwork")
    assert_equal "WiFi", network.network_type
    assert_equal "TestCarrier", network.carrier
    assert_equal "tower123", network.cell_tower_id
    assert_equal "TestNetwork", network.wifi_ssid
  end

  def test_generator_from_file
    generator = ProofMode::Generator.new(
      storage_path: @storage_path,
      email: @test_email,
      passphrase: @test_passphrase
    )
    
    # Create a test file
    temp_file = File.join(@storage_path, "test.txt")
    File.write(temp_file, "Test content")
    
    # Generate proof from file
    proof_hash = generator.generate_from_file(temp_file, {"description" => "Test"})
    assert_not_nil proof_hash
    assert_instance_of String, proof_hash
  end

  def test_generator_from_data
    generator = ProofMode::Generator.new(
      storage_path: @storage_path,
      email: @test_email,
      passphrase: @test_passphrase
    )
    
    # Generate proof from data
    test_data = "Test content"
    proof_hash = generator.generate_from_data(test_data, {"description" => "Test data"})
    assert_not_nil proof_hash
    assert_instance_of String, proof_hash
  end

  def test_checker_files
    checker = ProofMode::Checker.new
    
    # Create a test file
    temp_file = File.join(@storage_path, "test.txt")
    File.write(temp_file, "Test content")
    
    # Check files
    result = checker.check_files([temp_file])
    assert_not_nil result
    assert_instance_of String, result
    
    # Should be valid JSON
    require 'json'
    parsed_result = JSON.parse(result)
    assert parsed_result.key?("metadata")
  end
end