summaryrefslogtreecommitdiffstats
path: root/demo3/common/agl-service-homescreen/src/hs-client.h
blob: bd881e68bd865fc8fb6461b4337fc5b9a591698a (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
/*
 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HOMESCREEN_CLIENT_H
#define HOMESCREEN_CLIENT_H

#include <string>
#include <unordered_map>
#include "hs-helper.h"


class HS_Client {
public:
    HS_Client(struct afb_req request, const char* id) : HS_Client(request, std::string(id)){}
    HS_Client(struct afb_req request, std::string id);
    HS_Client(HS_Client&) = delete;
    HS_Client &operator=(HS_Client&) = delete;
    ~HS_Client();

    int tap_shortcut(const char* appname);
    int showWindow(struct afb_req request, const char* appname);
    int on_screen_message (struct afb_req request, const char* message);
    int on_screen_reply (struct afb_req request, const char* message);
    int subscribe(struct afb_req request, const char* event);
    int unsubscribe(struct afb_req request, const char* event);
    int allocateRestriction(struct afb_req request, const char* area);
    int releaseRestriction(struct afb_req request, const char* area);

private:
    bool checkEvent(const char* event);

private:
    std::string my_id;
    struct afb_event my_event;
    std::unordered_map<std::string, int> event_list;

};

#endif // HOMESCREEN_CLIENT_H
olor: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#! /usr/bin/env python3
#
# BitBake Toaster Implementation
#
# Copyright (C) 2013-2016 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-only
#

import re

from django.urls import reverse
from django.utils import timezone
from tests.browser.selenium_helpers import SeleniumTestCase

from orm.models import BitbakeVersion, Release, Project, Build
from orm.models import ProjectVariable

class TestAllProjectsPage(SeleniumTestCase):
    """ Browser tests for projects page /projects/ """

    PROJECT_NAME = 'test project'
    CLI_BUILDS_PROJECT_NAME = 'command line builds'
    MACHINE_NAME = 'delorean'

    def setUp(self):
        """ Add default project manually """
        project = Project.objects.create_project(self.CLI_BUILDS_PROJECT_NAME, None)
        self.default_project = project
        self.default_project.is_default = True
        self.default_project.save()

        # this project is only set for some of the tests
        self.project = None

        self.release = None

    def _add_build_to_default_project(self):
        """ Add a build to the default project (not used in all tests) """
        now = timezone.now()
        build = Build.objects.create(project=self.default_project,
                                     started_on=now,
                                     completed_on=now)
        build.save()

    def _add_non_default_project(self):
        """ Add another project """
        bbv = BitbakeVersion.objects.create(name='test bbv', giturl='/tmp/',
                                            branch='master', dirpath='')
        self.release = Release.objects.create(name='test release',
                                              branch_name='master',
                                              bitbake_version=bbv)
        self.project = Project.objects.create_project(self.PROJECT_NAME, self.release)
        self.project.is_default = False
        self.project.save()

        # fake the MACHINE variable
        project_var = ProjectVariable.objects.create(project=self.project,
                                                     name='MACHINE',
                                                     value=self.MACHINE_NAME)
        project_var.save()

    def _get_row_for_project(self, project_name):
        """ Get the HTML row for a project, or None if not found """
        self.wait_until_present('#projectstable tbody tr')
        rows = self.find_all('#projectstable tbody tr')

        # find the row with a project name matching the one supplied
        found_row = None
        for row in rows:
            if re.search(project_name, row.get_attribute('innerHTML')):
                found_row = row
                break

        return found_row

    def test_default_project_hidden(self):
        """
        The default project should be hidden if it has no builds
        and we should see the "no results" area
        """
        url = reverse('all-projects')
        self.get(url)
        self.wait_until_visible('#empty-state-projectstable')

        rows = self.find_all('#projectstable tbody tr')
        self.assertEqual(len(rows), 0, 'should be no projects displayed')

    def test_default_project_has_build(self):
        """ The default project should be shown if it has builds """
        self._add_build_to_default_project()

        url = reverse('all-projects')
        self.get(url)

        default_project_row = self._get_row_for_project(self.default_project.name)

        self.assertNotEqual(default_project_row, None,
                            'default project "cli builds" should be in page')

    def test_default_project_release(self):
        """
        The release for the default project should display as
        'Not applicable'
        """
        # need a build, otherwise project doesn't display at all
        self._add_build_to_default_project()

        # another project to test, which should show release
        self._add_non_default_project()

        self.get(reverse('all-projects'))
        self.wait_until_visible("#projectstable tr")

        # find the row for the default project
        default_project_row = self._get_row_for_project(self.default_project.name)

        # check the release text for the default project
        selector = 'span[data-project-field="release"] span.text-muted'
        element = default_project_row.find_element_by_css_selector(selector)
        text = element.text.strip()
        self.assertEqual(text, 'Not applicable',
                         'release should be "not applicable" for default project')

        # find the row for the default project
        other_project_row = self._get_row_for_project(self.project.name)

        # check the link in the release cell for the other project
        selector = 'span[data-project-field="release"]'
        element = other_project_row.find_element_by_css_selector(selector)
        text = element.text.strip()
        self.assertEqual(text, self.release.name,
                         'release name should be shown for non-default project')

    def test_default_project_machine(self):
        """
        The machine for the default project should display as
        'Not applicable'
        """
        # need a build, otherwise project doesn't display at all
        self._add_build_to_default_project()

        # another project to test, which should show machine
        self._add_non_default_project()

        self.get(reverse('all-projects'))

        self.wait_until_visible("#projectstable tr")

        # find the row for the default project
        default_project_row = self._get_row_for_project(self.default_project.name)

        # check the machine cell for the default project
        selector = 'span[data-project-field="machine"] span.text-muted'
        element = default_project_row.find_element_by_css_selector(selector)
        text = element.text.strip()
        self.assertEqual(text, 'Not applicable',
                         'machine should be not applicable for default project')

        # find the row for the default project
        other_project_row = self._get_row_for_project(self.project.name)

        # check the link in the machine cell for the other project
        selector = 'span[data-project-field="machine"]'
        element = other_project_row.find_element_by_css_selector(selector)
        text = element.text.strip()
        self.assertEqual(text, self.MACHINE_NAME,
                         'machine name should be shown for non-default project')

    def test_project_page_links(self):
        """
        Test that links for the default project point to the builds
        page /projects/X/builds for that project, and that links for
        other projects point to their configuration pages /projects/X/
        """

        # need a build, otherwise project doesn't display at all
        self._add_build_to_default_project()

        # another project to test
        self._add_non_default_project()

        self.get(reverse('all-projects'))

        # find the row for the default project
        default_project_row = self._get_row_for_project(self.default_project.name)

        # check the link on the name field
        selector = 'span[data-project-field="name"] a'
        element = default_project_row.find_element_by_css_selector(selector)
        link_url = element.get_attribute('href').strip()
        expected_url = reverse('projectbuilds', args=(self.default_project.id,))
        msg = 'link on default project name should point to builds but was %s' % link_url
        self.assertTrue(link_url.endswith(expected_url), msg)

        # find the row for the other project
        other_project_row = self._get_row_for_project(self.project.name)

        # check the link for the other project
        selector = 'span[data-project-field="name"] a'
        element = other_project_row.find_element_by_css_selector(selector)
        link_url = element.get_attribute('href').strip()
        expected_url = reverse('project', args=(self.project.id,))
        msg = 'link on project name should point to configuration but was %s' % link_url
        self.assertTrue(link_url.endswith(expected_url), msg)