File: test-dmap-container-db.c

package info (click to toggle)
libdmapsharing 2.9.39-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,640 kB
  • sloc: ansic: 15,629; sh: 4,443; makefile: 444; xml: 53
file content (88 lines) | stat: -rw-r--r-- 2,606 bytes parent folder | download | duplicates (5)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Database class for DMAP sharing
 *
 * Copyright (C) 2008 W. Michael Petullo <mike@flyn.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "test-dmap-container-db.h"

/* This test implementation of the DMAPContainerDb interface allows for one
 * record.  Normally, one would befine some data structure to contain
 * multiple records.
 */
static DMAPContainerRecord *record = NULL;

static DMAPContainerRecord *
test_dmap_container_db_lookup_by_id (DMAPContainerDb *db, guint id)
{
	/* In reality, lookup the proper record and return it. */
	return g_object_ref (record);
}

static void
test_dmap_container_db_foreach (DMAPContainerDb *db,
				GHFunc func,
				gpointer data)
{
	/* In reality, pull each record from the db and execute func on it. */
        func (GUINT_TO_POINTER (1), record, data);
}

static gint64
test_dmap_container_db_count (DMAPContainerDb *db)
{
	/* In reality, return the record count. */
	return 1;
}

static void
test_dmap_container_db_init (TestDMAPContainerDb *db)
{
}

static void
test_dmap_container_db_class_init (TestDMAPContainerDbClass *klass)
{
}

static void
test_dmap_container_db_interface_init (gpointer iface, gpointer data)
{
	DMAPContainerDbIface *dmap_container_db = iface;

	g_assert (G_TYPE_FROM_INTERFACE (dmap_container_db) == DMAP_TYPE_CONTAINER_DB);

	dmap_container_db->lookup_by_id = test_dmap_container_db_lookup_by_id;
	dmap_container_db->foreach = test_dmap_container_db_foreach;
	dmap_container_db->count = test_dmap_container_db_count;
}

G_DEFINE_TYPE_WITH_CODE (TestDMAPContainerDb, test_dmap_container_db, G_TYPE_OBJECT, 
			 G_IMPLEMENT_INTERFACE (DMAP_TYPE_CONTAINER_DB,
						test_dmap_container_db_interface_init))

TestDMAPContainerDb *
test_dmap_container_db_new (DMAPContainerRecord *r)
{
	TestDMAPContainerDb *db;

	db = TEST_DMAP_CONTAINER_DB (g_object_new (TYPE_TEST_DMAP_CONTAINER_DB, NULL));

	record = r;

	return db;
}