Remove test code

This commit is contained in:
Wvader 2022-11-02 17:12:19 +00:00
parent 538807da1b
commit b136e35b31
1 changed files with 32 additions and 14 deletions

View File

@ -20,11 +20,9 @@ static void testGet() {
struct augeas *aug;
char *s;
aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
r = aug_load_file(aug, "/etc/hosts");
r = aug_source(aug, "/files/etc/hosts/1", &s);
std::cout << "The value read from node: " << s << std::endl;
@ -32,7 +30,7 @@ static void testGet() {
aug_close(aug);
}
static void testAugPreview() {
static void readHostsFile() {
struct augeas *aug;
int r;
char *s;
@ -42,20 +40,41 @@ static void testAugPreview() {
int readsz = 0;
/* Read the original contents of the etc/hosts file */
if (asprintf(&etc_hosts_fn,"%s/etc/hosts",root) >=0 ) {
hosts_fp = fopen(etc_hosts_fn,"r");
if ( hosts_fp ) {
if (asprintf(&etc_hosts_fn, "%s/etc/hosts", root) >= 0) {
hosts_fp = fopen(etc_hosts_fn, "r");
if (hosts_fp) {
hosts_txt = static_cast<char *>(calloc(sizeof(char), 4096));
if ( hosts_txt ) {
readsz = fread(hosts_txt,sizeof(char),4096,hosts_fp);
*(hosts_txt+readsz) = '\0';
if (hosts_txt) {
readsz = fread(hosts_txt, sizeof(char), 4096, hosts_fp);
*(hosts_txt + readsz) = '\0';
}
fclose(hosts_fp);
}
free(etc_hosts_fn);
}
aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
r = aug_load_file(aug, "/etc/hosts");
r = aug_preview(aug, "/files/etc/hosts/1", &s);
std::cout << s << std::endl;
free(hosts_txt);
free(s);
aug_close(aug);
}
static void readHostsTree() {
struct augeas *aug;
int r;
char *s;
char *etc_hosts_fn = NULL;
FILE *hosts_fp = NULL;
char *hosts_txt = NULL;
int readsz = 0;
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
r = aug_load_file(aug, "/etc/hosts");
r = aug_preview(aug, "/files/etc/hosts/1", &s);
@ -68,10 +87,9 @@ static void testAugPreview() {
}
int main(int argc, char *argv[]) {
testGet();
testAugPreview();
testGet();
readHostsFile();
return 0;
}