messenger-android

Android graphical user interfaces for GNUnet Messenger
Log | Files | Refs | README | LICENSE

run_client_tests.sh (3934B)


      1 #!/bin/bash
      2 
      3 # GNUnet Messenger Client Test Script
      4 # Assumes server is already installed and running
      5 # Usage: ./run_client_tests.sh
      6 
      7 set -e  # Exit on error
      8 
      9 echo "========================================="
     10 echo "GNUnet Messenger Client Tests"
     11 echo "========================================="
     12 echo ""
     13 
     14 # Colors
     15 GREEN='\033[0;32m'
     16 RED='\033[0;31m'
     17 YELLOW='\033[1;33m'
     18 NC='\033[0m'
     19 
     20 print_success() {
     21     echo -e "${GREEN}✓ $1${NC}"
     22 }
     23 
     24 print_error() {
     25     echo -e "${RED}✗ $1${NC}"
     26 }
     27 
     28 print_warning() {
     29     echo -e "${YELLOW}⚠ $1${NC}"
     30 }
     31 
     32 # Check ADB
     33 echo "Checking prerequisites..."
     34 if ! command -v adb &> /dev/null; then
     35     print_error "adb not found"
     36     exit 1
     37 fi
     38 print_success "ADB found"
     39 
     40 # Check device
     41 echo ""
     42 echo "Checking Android device connection..."
     43 DEVICES=$(adb devices | grep -v "List of devices" | grep -v "^$" | wc -l)
     44 if [ "$DEVICES" -eq 0 ]; then
     45     print_error "No Android device connected"
     46     exit 1
     47 fi
     48 if [ "$DEVICES" -gt 1 ]; then
     49     print_warning "Multiple devices detected. Using first device."
     50 fi
     51 print_success "Device connected"
     52 
     53 # Check server is installed
     54 echo ""
     55 echo "Checking for GNUnet server app..."
     56 if ! adb shell pm list packages | grep -q "org.gnu.gnunet"; then
     57     print_error "Server app not installed"
     58     echo "Please install server first from gnunet-android directory:"
     59     echo "  cd ../gnunet-android/android_studio && ./gradlew installDebug"
     60     exit 1
     61 fi
     62 print_success "Server app found: org.gnu.gnunet"
     63 
     64 # Check if server is running
     65 echo ""
     66 echo "Checking server status..."
     67 SERVER_PID=$(adb shell pidof org.gnu.gnunet || echo "")
     68 if [ -z "$SERVER_PID" ]; then
     69     print_warning "Server not running - starting it..."
     70     adb shell am start -n org.gnu.gnunet/.MainActivity > /dev/null 2>&1
     71     sleep 3
     72     print_success "Server started"
     73 else
     74     print_success "Server already running (PID: $SERVER_PID)"
     75 fi
     76 
     77 # Build client APK
     78 echo ""
     79 echo "========================================="
     80 echo "Step 1: Build Client App"
     81 echo "========================================="
     82 echo ""
     83 
     84 if ./GNUnetMessenger/gradlew assembleDebug > /dev/null 2>&1; then
     85     print_success "Client APK built successfully"
     86 else
     87     print_error "Failed to build client APK"
     88     exit 1
     89 fi
     90 
     91 # Install client
     92 echo ""
     93 echo "========================================="
     94 echo "Step 2: Install/Update Client App"
     95 echo "========================================="
     96 echo ""
     97 
     98 if ./GNUnetMessenger/gradlew installDebug > /dev/null 2>&1; then
     99     print_success "Client app installed/updated"
    100 else
    101     print_error "Failed to install client app"
    102     exit 1
    103 fi
    104 
    105 # Run tests
    106 echo ""
    107 echo "========================================="
    108 echo "Step 3: Run Instrumentation Tests"
    109 echo "========================================="
    110 echo ""
    111 
    112 ./GNUnetMessenger/gradlew connectedAndroidTest
    113 TEST_RESULT=$?
    114 
    115 # Display results
    116 echo ""
    117 echo "========================================="
    118 echo "Test Results"
    119 echo "========================================="
    120 
    121 if [ $TEST_RESULT -eq 0 ]; then
    122     print_success "All tests passed!"
    123     echo ""
    124     echo "Test report location:"
    125     echo "  ./GNUnetMessenger/app/build/reports/androidTests/connected/index.html"
    126 else
    127     print_error "Some tests failed"
    128     echo ""
    129     echo "Test report location:"
    130     echo "  ./GNUnetMessenger/app/build/reports/androidTests/connected/index.html"
    131     echo ""
    132     echo "Check logs for details:"
    133     echo "  adb logcat | grep -E 'GnunetChatIpcService|GnunetChatBoundService'"
    134 fi
    135 
    136 # Offer to view logs
    137 echo ""
    138 read -p "View logs now? (y/n) " -n 1 -r
    139 echo
    140 if [[ $REPLY =~ ^[Yy]$ ]]; then
    141     echo ""
    142     echo "========================================="
    143     echo "GNUnet Logs (Ctrl+C to exit)"
    144     echo "========================================="
    145     echo ""
    146     adb logcat | grep -E "GnunetChatIpcService|GnunetChatBoundService|GNUNET"
    147 fi
    148 
    149 echo ""
    150 echo "========================================="
    151 echo "Test execution completed!"
    152 echo "========================================="