aboutsummaryrefslogblamecommitdiffstats
path: root/test-variables.c
blob: 0049aadb9669a31479914ac7ccb15523bc47388f (plain) (tree)

































































                                                                         
                                 



                                        

                                            

                                                        
                                                                        




                                                                                                            




                                                                       
                            



                 
/* See LICENSE file for copyright and license details. */
#include "libenv.h"
#include <assert.h> /* TODO improve output */
#include <stdio.h>


#define ELEMSOF(A) (sizeof(A) / sizeof(*(A)))


static const char *class_names[] = {
	"LIBENV_END",
	"display",
	"display-config",
	"desktop",
	"terminal-caps",
	"local-terminal",
	"locale",
	"timezone",
	"session",
	"theme-config",
	"theme-plugin",
	"internet",
	"audio",
	"user",
	"applications",
	"preferences",
	"system-paths",
	"user-paths",
	"pwd",
	"exec",
	"path",
	"remote-unsafe",
	"remote-safe",
	"login-unsafe",
	"login-safe",
	"su-unsafe",
	"su-safe"
};


int
main(void)
{
	const struct libenv_variable *vars;
	size_t nclasswords1 = 0, nclasswords2 = 1, nclasswords;
	size_t count1 = 0, count2 = 1, count;
	size_t i, j;

	assert(vars = libenv_get_complete_list(NULL, NULL));
	assert(vars == libenv_get_complete_list(&nclasswords1, NULL));
	assert(vars == libenv_get_complete_list(NULL, &count1));
	assert(vars == libenv_get_complete_list(&nclasswords2, &count2));
	assert(vars == libenv_get_complete_list(&nclasswords, &count));

	assert(nclasswords1 == nclasswords2);
	assert(nclasswords1 == nclasswords);
	assert(count1 == count2);
	assert(count1 == count);

	assert(!vars[count].name);
	assert(!vars[count].classes);

	assert(nclasswords == (ELEMSOF(class_names) + 63) / 64);

	for (i = 0; i < count; i++) {
		const char *prefix = " ";
		uint64_t any = 0;

		assert(vars[i].name);
		assert(*vars[i].name);
		assert(vars[i].classes);

		printf("%s:", vars[i].name);
		for (j = 0; j < nclasswords * 64; j++) {
			any |= vars[i].classes[j / 64];
			if ((vars[i].classes[j / 64] >> (j % 64)) & 1) {
				assert(j != (size_t)LIBENV_END);
				if (j >= ELEMSOF(class_names)) {
					fprintf(stderr, "\033[1;31mclass name list is out of date\033[m\n");
					return 1;
				}
				printf("%s%s", prefix, class_names[j]);
				prefix = ", ";
			}
		}
		printf("\n");
		assert(any);
	}

	return 0;
}