Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  mock_stat.c

  Sprache: C
 

/*++
/* NAME
/* mock_stat 3
/* SUMMARY
/* test scaffolding
/* SYNOPSIS
/* #include <mock_stat.h>
/*
/* typedef struct MOCK_STAT_REQ {
/* .in +4
/* const char *want_path;
/* int out_errno;
/* struct stat st;
/* .in -4
/* } MOCK_STAT_REQ;
/*
/* void setup_mock_stat(const MOCK_STAT_REQ *request)
/*
/* void teardown_mock_stat(void)
/* DESCRIPTION
/* This module provides a mock stat() implementation that returns
/* static results for expected calls.
/*
/* setup_mock_stat() adds a mapping from pathname to struct
/* stat_info pointer. It is an error to enter multiple mappings
/* for one pathname. If makes a shallow copy ig its input:
/* .IP want_path
/* The lookup key for file status information.
/* .IP out_errno
/* If non-zero, mock stat() will return -1 and set the global
/* errno variable.
/* .IP st
/* File status information, ignored when out_errno is non-zero.
/* .PP
/* teardown_mock_stat() destroys all mappings entered with
/* setup_mock_stat().
/*
/* The mock stat() function looks up the MOCK_STAT_REQ information
/* for a pathname and terminates the test if the pathname is not
/* expected. If the mapping contains a non-zero out_errno value,
/* it simulates an error, sets the global errno value, and returns
/* -1.  Otherwise it copies the stat_info.st value to the storage
/* provided with the st argument.
/* SEE ALSO
/* stat(2), the real thing
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* porcupine.org
/*--*/


 /*
  * System library.
  */

#include <sys_defs.h>
#include <errno.h>
#include <sys/stat.h>

 /*
  * Utility library.
  */

#include <htable.h>
#include <msg.h>
#include <wrap_stat.h>

 /*
  * Test library.
  */

#include <mock_stat.h>

 /*
  * Application-specific.
  */

static HTABLE *mock_stat_table;

/* setup_mock_stat - add path-to-status mapping */

void    setup_mock_stat(const MOCK_STAT_REQ *request)
{
    if (mock_stat_table == 0)
 mock_stat_table = htable_create(10);
    htable_enter(mock_stat_table, request->want_path, (void *) request);
}

/* teardown_mock_stat - destroy all path-to-status mappings */

void    teardown_mock_stat(void)
{
    if (mock_stat_table) {
 htable_free(mock_stat_table, (void (*) (void *)) 0);
 mock_stat_table = 0;
    }
}

/* stat - mock stat() implementation */

int stat(const char *path, struct stat *st) {
    MOCK_STAT_REQ *mock_info;

    if ((mock_info = (MOCK_STAT_REQ *) htable_find(mock_stat_table, path)) == 0)
 msg_fatal("mock stat: unexpected pathname: '%s'", path);

    if (mock_info->out_errno != 0) {
 errno = mock_info->out_errno;
 return (-1);
    } else {
 *st = mock_info->out_st;
 return (0);
    }
}

Messung V0.5 in Prozent
C=76 H=94 G=85

¤ Dauer der Verarbeitung: 0.22 Sekunden  (vorverarbeitet am  2026-08-08) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=141584
#Domains=752002