1 | /*
|
---|
2 | * Copyright (c) 2015 Michal Koutny
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <assert.h>
|
---|
30 |
|
---|
31 | #include "../edge.h"
|
---|
32 |
|
---|
33 | #include "mock_unit.h"
|
---|
34 |
|
---|
35 | unit_t *mock_units[MAX_TYPES][MAX_UNITS];
|
---|
36 |
|
---|
37 | unit_type_t unit_types[] = {
|
---|
38 | UNIT_CONFIGURATION,
|
---|
39 | UNIT_MOUNT,
|
---|
40 | UNIT_SERVICE,
|
---|
41 | UNIT_TARGET
|
---|
42 | };
|
---|
43 |
|
---|
44 | void mock_create_units(void)
|
---|
45 | {
|
---|
46 | for (int i = 0; i < MAX_TYPES; ++i) {
|
---|
47 | unit_type_t type = unit_types[i];
|
---|
48 | for (int j = 0; j < MAX_UNITS; ++j) {
|
---|
49 | mock_units[type][j] = unit_create(type);
|
---|
50 | assert(mock_units[type][j] != NULL);
|
---|
51 |
|
---|
52 | asprintf(&mock_units[type][j]->name, "%u_%u", type, j);
|
---|
53 | assert(mock_units[type][j]->name != NULL);
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | void mock_destroy_units(void)
|
---|
59 | {
|
---|
60 | for (int i = 0; i < MAX_TYPES; ++i) {
|
---|
61 | unit_type_t type = unit_types[i];
|
---|
62 | for (int j = 0; j < MAX_UNITS; ++j) {
|
---|
63 | unit_destroy(&mock_units[type][j]);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | void mock_set_units_state(unit_state_t state)
|
---|
69 | {
|
---|
70 | for (int i = 0; i < MAX_TYPES; ++i) {
|
---|
71 | unit_type_t type = unit_types[i];
|
---|
72 | for (int j = 0; j < MAX_UNITS; ++j) {
|
---|
73 | mock_units[type][j]->state = state;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | void mock_add_edge(unit_t *input, unit_t *output)
|
---|
79 | {
|
---|
80 | int rc = edge_connect(input, output);
|
---|
81 | assert(rc == EOK);
|
---|
82 |
|
---|
83 | link_t *link = list_last(&input->edges_out);
|
---|
84 | unit_edge_t *e =
|
---|
85 | list_get_instance(link, unit_edge_t, edges_out);
|
---|
86 | e->commited = true;
|
---|
87 | }
|
---|
88 |
|
---|
89 | int mock_unit_vmt_start_sync(unit_t *unit)
|
---|
90 | {
|
---|
91 | unit->state = STATE_STARTED;
|
---|
92 | return EOK;
|
---|
93 | }
|
---|
94 |
|
---|
95 | int mock_unit_vmt_start_async(unit_t *unit)
|
---|
96 | {
|
---|
97 | unit->state = STATE_STARTING;
|
---|
98 | return EOK;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void mock_unit_vmt_exposee_created(unit_t *unit)
|
---|
102 | {
|
---|
103 | unit->state = STATE_STARTED;
|
---|
104 | unit_notify_state(unit);
|
---|
105 | }
|
---|
106 |
|
---|