1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/tests/depend.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/*********************************************************************** 1.10 +** 1996 - Netscape Communications Corporation 1.11 +** 1.12 +** 1.13 +** Name: depend.c 1.14 +** Description: Test to enumerate the dependencies 1.15 +* 1.16 +** Modification History: 1.17 +** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. 1.18 +** The debug mode will print all of the printfs associated with this test. 1.19 +** The regress mode will be the default mode. Since the regress tool limits 1.20 +** the output to a one line status:PASS or FAIL,all of the printf statements 1.21 +** have been handled with an if (debug_mode) statement. 1.22 +***********************************************************************/ 1.23 +#include "prinit.h" 1.24 + 1.25 +/*********************************************************************** 1.26 +** Includes 1.27 +***********************************************************************/ 1.28 +/* Used to get the command line option */ 1.29 +#include "plgetopt.h" 1.30 + 1.31 +#include <stdio.h> 1.32 +#include <stdlib.h> 1.33 + 1.34 +static void PrintVersion( 1.35 + const char *msg, const PRVersion* info, PRIntn tab) 1.36 +{ 1.37 + static const len = 20; 1.38 + static const char *tabs = {" "}; 1.39 + 1.40 + tab *= 2; 1.41 + if (tab > len) tab = len; 1.42 + printf("%s", &tabs[len - tab]); 1.43 + printf("%s ", msg); 1.44 + printf("%s ", info->id); 1.45 + printf("%d.%d", info->major, info->minor); 1.46 + if (0 != info->patch) 1.47 + printf(".p%d", info->patch); 1.48 + printf("\n"); 1.49 +} /* PrintDependency */ 1.50 + 1.51 +static void ChaseDependents(const PRVersionInfo *info, PRIntn tab) 1.52 +{ 1.53 + PrintVersion("exports", &info->selfExport, tab); 1.54 + if (NULL != info->importEnumerator) 1.55 + { 1.56 + const PRDependencyInfo *dependent = NULL; 1.57 + while (NULL != (dependent = info->importEnumerator(dependent))) 1.58 + { 1.59 + const PRVersionInfo *import = dependent->exportInfoFn(); 1.60 + PrintVersion("imports", &dependent->importNeeded, tab); 1.61 + ChaseDependents(import, tab + 1); 1.62 + } 1.63 + } 1.64 +} /* ChaseDependents */ 1.65 + 1.66 +static PRVersionInfo hack_export; 1.67 +static PRVersionInfo dummy_export; 1.68 +static PRDependencyInfo dummy_imports[2]; 1.69 + 1.70 +static const PRVersionInfo *HackExportInfo(void) 1.71 +{ 1.72 + hack_export.selfExport.major = 11; 1.73 + hack_export.selfExport.minor = 10; 1.74 + hack_export.selfExport.patch = 200; 1.75 + hack_export.selfExport.id = "Hack"; 1.76 + hack_export.importEnumerator = NULL; 1.77 + return &hack_export; 1.78 +} 1.79 + 1.80 +static const PRDependencyInfo *DummyImports( 1.81 + const PRDependencyInfo *previous) 1.82 +{ 1.83 + if (NULL == previous) return &dummy_imports[0]; 1.84 + else if (&dummy_imports[0] == previous) return &dummy_imports[1]; 1.85 + else if (&dummy_imports[1] == previous) return NULL; 1.86 +} /* DummyImports */ 1.87 + 1.88 +static const PRVersionInfo *DummyLibVersion(void) 1.89 +{ 1.90 + dummy_export.selfExport.major = 1; 1.91 + dummy_export.selfExport.minor = 0; 1.92 + dummy_export.selfExport.patch = 0; 1.93 + dummy_export.selfExport.id = "Dumbass application"; 1.94 + dummy_export.importEnumerator = DummyImports; 1.95 + 1.96 + dummy_imports[0].importNeeded.major = 2; 1.97 + dummy_imports[0].importNeeded.minor = 0; 1.98 + dummy_imports[0].importNeeded.patch = 0; 1.99 + dummy_imports[0].importNeeded.id = "Netscape Portable Runtime"; 1.100 + dummy_imports[0].exportInfoFn = PR_ExportInfo; 1.101 + 1.102 + dummy_imports[1].importNeeded.major = 5; 1.103 + dummy_imports[1].importNeeded.minor = 1; 1.104 + dummy_imports[1].importNeeded.patch = 2; 1.105 + dummy_imports[1].importNeeded.id = "Hack Library"; 1.106 + dummy_imports[1].exportInfoFn = HackExportInfo; 1.107 + 1.108 + return &dummy_export; 1.109 +} /* DummyLibVersion */ 1.110 + 1.111 +int main(int argc, char **argv) 1.112 +{ 1.113 + PRIntn tab = 0; 1.114 + const PRVersionInfo *info = DummyLibVersion(); 1.115 + const char *buildDate = __DATE__, *buildTime = __TIME__; 1.116 + 1.117 + printf("Depend.c build time is %s %s\n", buildDate, buildTime); 1.118 + 1.119 + if (NULL != info) ChaseDependents(info, tab); 1.120 + 1.121 + return 0; 1.122 +} /* main */ 1.123 + 1.124 +/* depend.c */