summaryrefslogtreecommitdiffstats
path: root/tests/test_auth_enum_actions.cpp
blob: 8a9030ff769906af482fc430123f966c59c39eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#include <tqstring.h>

#include "core/polkit-tqt-authority.h"
#include "core/polkit-tqt-details.h"

#define TEST_PASSED 0
#define TEST_FAILED 1

using namespace PolkitTQt;

void wait()
{
  for (int i = 0; i < 100; i++)
  {
    usleep(100);
  }
}

int main(void)
{
  // This needs the file org.tqt.policykit.examples.policy from examples to be installed
  ActionDescription::List list = Authority::instance()->enumerateActionsSync();
  if (Authority::instance()->hasError())
  {
    return TEST_FAILED;
  }
  // Check whether enumerateAction returns at least example actions
  int count = 0;
  for (const ActionDescription &actionDesc : list)
  {
    if ((actionDesc.actionId() == "org.tqt.policykit.examples.kick") ||
        (actionDesc.actionId() == "org.tqt.policykit.examples.cry") ||
        (actionDesc.actionId() == "org.tqt.policykit.examples.bleed"))
    {
      count++;
    }
  }
  if (count != 3)
  {
    return TEST_FAILED;
  }

  // Test cancelling the enumeration
  Authority::instance()->enumerateActions();
  Authority::instance()->enumerateActionsCancel();
  wait();
  if (Authority::instance()->hasError())
  {
    return TEST_FAILED;
  }

  return TEST_PASSED;
}