#!/bin/sh
# ------------------------------------------------------------------
#
#    Copyright (C) 2014 Canonical Ltd.
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of version 2 of the GNU General Public
#    License published by the Free Software Foundation.
#
# ------------------------------------------------------------------

set -e

rc="0"
for framework in ubuntu-sdk-13.10 ubuntu-sdk-14.04 ubuntu-sdk-14.04-qml ubuntu-sdk-14.04-html ubuntu-sdk-14.04-papi ; do
    expected=""
    case "$framework" in
        ubuntu-sdk-13.10)
            expected="1.0"
            ;;
        ubuntu-sdk-14.04*)
            expected="1.1"
            ;;
    esac
    v=`aa-clickquery -q policy_version --click-framework=$framework` || {
        rc="1"
        echo "aa-clickquery exited with error" >&2
        continue
    }
    if [ "$v" != "$expected" ]; then
        echo "Wrong version for '$framework' ($v != $expected)" >&2
        rc="1"
    fi
done

for framework in ubuntu-sdk-13.04 nonexistent ubuntu-sdk-14.05-qml ; do
    if aa-clickquery -q policy_version --click-framework=$framework >/dev/null 2>&1 ; then
        echo "Unexpected return code '0' for '$framework'" >&2
        rc="1"
    fi
done

if [ "$rc" = "0" ]; then
    echo PASS
else
    echo FAIL
fi

exit $rc
